phpDocumentor をインストールしてみた。

phpdoc を使いなさいと言われたので、インストールしてみました。

あと、vim でコメントのひな形をいれれるようにしました。

環境

  • OS: Ubuntu 12.04 64bit
  • PHP: PHP 5.3.10-1ubuntu3.6 with Suhosin-Patch
  • phpDocumentor: 2.0.0a12
  • Vim: 7.3
    • vim-doc.vim: 1.0.1

Vim に phpdoc コメント生成プラグインを入れる

これがよさげ。

PDV - phpDocumentor for Vim

http://www.vim.org/scripts/script.php?script_id=1355

bundle を利用してインストール。

Bundle を利用してインストールするので .vimrc に以下を追記。

.vimrc
1
Bundle 'PDV--phpDocumentor-for-Vim'

追記後に :BundleInstall を実行してインストール。

PDV の設定をする。

デフォルトのコメント設定をするため php-doc.vim の77行目〜83行目あたりにある下記を変更する。

~/.vim/bundle/PDV--phpDocumentor-for-Vim/plugin/php-doc.vim
1
2
3
4
5
6
7
" Default values
let g:pdv_cfg_Type = "mixed"
let g:pdv_cfg_Package = ""
let g:pdv_cfg_Version = "$id$"
let g:pdv_cfg_Author = "Tobias Schlitt <toby@php.net>"
let g:pdv_cfg_Copyright = "1997-2005 The PHP Group"
let g:pdv_cfg_License = "PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}"

今回は Auhor くらいしか入れないみたいなので下記に変更。

~/.vim/bundle/PDV--phpDocumentor-for-Vim/plugin/php-doc.vim
1
2
3
4
5
6
7
" Default values
let g:pdv_cfg_Type = "mixed"
let g:pdv_cfg_Package = ""
let g:pdv_cfg_Version = ""
let g:pdv_cfg_Author = "nanigashi <nanigashi@example.com>"
let g:pdv_cfg_Copyright = ""
let g:pdv_cfg_License = ""

キーバインドも変更。

.vimrc
1
2
3
inoremap <C-P> <ESC>:call PhpDocSingle()<CR>i
nnoremap <C-P> :call PhpDocSingle()<CR>
vnoremap <C-P> :call PhpDocRange()<CR>

phpdoc のコメントを入れてみる。

class の場合は class の行で、function の場合は function が記述してある行で Ctrl + P で自動でひな形が入る。

doctest.php
1
2
3
4
5
6
<?php
class Hoge {
function Foo($bar, $piyo, $fuga=array(), $hogera=null) {
return $bar;
}
}

このコードで実行すると下記になる。

doctest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
/**
* Hoge
*
* @package
* @version
* @copyright
* @author nanigashi <nanigashi@example.com>
* @license
*/
class Hoge {
/**
* Foo
*
* @param mixed $bar
* @param mixed $piyo
* @param array $fuga
* @param mixed $hogera
* @access public
* @return void
*/
function Foo($bar, $piyo, $fuga=array(), $hogera=null) {
return $bar;
}
}

phpDocumentor で phpdoc を生成する。

phpDocumentor 2

http://www.phpdoc.org/

Pear のインストール

pearを利用しているようなのでインストールする。

Terminal
1
$ sudo apt-get install php-pear

phpDocumentor のインストール

チャンネルを登録後、インストールする。

Terminal
1
2
$ sudo pear channel-discover pear.phpdoc.org
$ sudo pear install phpdoc/phpDocumentor-alpha

インストールされているか確認。

Terminal
1
2
$ phpdoc --version
phpDocumentor version 2.0.0a12

phpdocの生成方法。

phpdoc run -d [input_path] -t [output_path]

phpdoc を生成してみる。

試しにコマンド実行。

Terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ phpdoc run -d . -t ./doc
Initializing parser and collecting files .. OK
Parsing files
Parsing /home/nanigashi/phpdoc_test/doctest.php
No page-level DocBlock was found in file doctest.php
Storing structure.xml in "/home/nanigashi/phpdoc_test/doc/structure.xml" .. OK
Initializing transformer .. OK
Processing behaviours .. OK
Executing transformations



[phpDocumentor\Plugin\Core\Exception]
The XSL writer was unable to find your XSLTProcessor; please check if you have installed the PHP XSL extension



project:run [-t|--target[="..."]] [-f|--filename[="..."]] [-d|--directory[="..."]] [--encoding[="..."]] [-e|--extensions[="..."]] [-i|--ignore[="..."]] [--ignore-tags[="..."]] [--hidden] [--ignore-symlinks] [-m|--markers[="..."]] [--title[="..."]] [--force] [--validate] [--visibility[="..."]] [--defaultpackagename[="..."]] [--sourcecode] [-p|--progressbar] [--template[="..."]] [--parseprivate] [-c|--config[="..."]]

実行してみると以下のエラーが発生。

The XSL writer was unable to find your XSLTProcessor; please check if you have installed the PHP XSL extension

調べてみると php5-xsl というのが必要のようなので以下でインストール。

Terminal
1
$ sudo aptitude install php5-xsl

再度実行。

Terminal
1
2
3
4
5
6
7
8
phpdoc run -d . -t doc/
Initializing parser and collecting files .. OK
Parsing files
Parsing /home/nanigashi/phpdoc_test/doctest.php
Storing structure.xml in "/home/nanigashi/phpdoc_test/doc/structure.xml" .. OK
Initializing transformer .. OK
Processing behaviours .. OK
Executing transformations

無事生成されました。

生成された doc/index.html をブラウザで開くと結構お洒落なドキュメントができます。

以上です。

© 2024 磁力式駆動 All Rights Reserved.
Theme by hiero