2013年3月28日木曜日

phpDocumentor:インストール

phpDocumentorを使ってみました。
pearの自動インストールで、バージョンは1.4.4です。
備忘録がてらまとめました。

phpDocumentor インストール

PEARから自動インストール
# pear install --alldeps phpdocumentor
No releases available for package "pear.php.net/phpdocumentor"
install failed
いきなりエラー。

原因は、インストールしようとしていたウェブサーバ(Linux)が社内ネットワーク上にあり、インターネットの外部接続にプロキシの認証が必要だったからです。
ブラウザを立ち上げて認証し、再び実行。

# pear install --alldeps phpdocumentor
WARNING: "pear/PhpDocumentor" is deprecated in favor of "channel://pear.phpdoc.org/phpdocumentor"
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update
WARNING: "pear/XML_Parser" is deprecated in favor of "pear/XML_Parser2"
downloading PhpDocumentor-1.4.4.tgz ...
Starting to download PhpDocumentor-1.4.4.tgz (1,534,088 bytes)
.....done: 1,534,088 bytes
downloading XML_Beautifier-1.2.2.tgz ...
Starting to download XML_Beautifier-1.2.2.tgz (14,587 bytes)
...done: 14,587 bytes
downloading XML_Parser-1.3.4.tgz ...
Starting to download XML_Parser-1.3.4.tgz (16,040 bytes)
...done: 16,040 bytes
install ok: channel://pear.php.net/PhpDocumentor-1.4.4
install ok: channel://pear.php.net/XML_Parser-1.3.4
install ok: channel://pear.php.net/XML_Beautifier-1.2.2

XMLパーサが重複しているWarningが出たものの、とりあえずOK.

# pear list
Installed packages, channel pear.php.net:
=========================================
PEAR             1.9.4   stable
PhpDocumentor    1.4.4   stable
XML_Beautifier   1.2.2   stable
XML_Parser       1.3.4   stable

ちゃんと入ってました。
これでphpDocumentorのインストールは終了です。

PHPのメモリエラー

インストール中に
Fatal error: Allowed memory size of  XXXXX bytes exhausted ...
のPHpメモリエラーが出た場合は、
php.iniのmemory_limitの設定を8Mないし未設定から16Mなど上に引き上げましょう。
私は最初から256Mあったので出ませんでした。(こんなになくとも良いです)

日本語文字化け対応

このまま出力するとコメントに含まれている日本語が文字化けします。
PhpDocumentorで使われているSmartyのテンプレート(header.tpl)にmetaタグでのエンコード指定がないか、デフォルトでiso-8859-1が指定されているからです。
そのため、header.tplテンプレートのエンコードをUTF-8(スクリプトのエンコード)指定を追記するか、iso-8859-1を書き換えます。
metaタグを追記する

<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>


metaタグをUTF-8に書き換える
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
→'text/html; charset=UTF-8'

修正対象テンプレート

[PEAR]:開発環境では[/usr/local/share/pear]
[TMP]:開発環境では[/data/PhpDocumentor/phpDocumentor/Converters/HTML]
・[PEAR][TMP]/frames/templates/phpedit/templates/header.tpl
・[PEAR][TMP]/frames/templates/phphtmllib/templates/header.tpl
・[PEAR][TMP]/frames/templates/DOM/phphtmllib/templates/header.tpl
・[PEAR][TMP]/frames/templates/DOM/earthli/templates/header.tpl
・[PEAR][TMP]/frames/templates/DOM/default/templates/header.tpl
・[PEAR][TMP]/frames/templates/DOM/l0l33t/templates/header.tpl
・[PEAR][TMP]/frames/templates/DOM/phpdoc.de/templates/header.tpl
・[PEAR][TMP]/frames/templates/earthli/templates/header.tpl
・[PEAR][TMP]/frames/templates/default/templates/header.tpl
・[PEAR][TMP]/frames/templates/l0l33t/templates/header.tpl
・[PEAR][TMP]/frames/templates/phpdoc.de/templates/header.tpl
・[PEAR][TMP]/Smarty/templates/HandS/templates/header.tpl
・[PEAR][TMP]/Smarty/templates/PHP/templates/header.tpl
・[PEAR][TMP]/Smarty/templates/PEAR/templates/header.tpl
・[PEAR][TMP]/Smarty/templates/default/templates/header.tpl

全て修正しても良いですし、自分の使うテンプレートだけでも良いと思います。
これで実行準備が整いました。

phpDocumentorを実行

ディレクトリ出力
phpdoc –pp -t ./doc -d ./website -o HTML:Smarty: HandS
ファイル出力
phpdoc -pp -t ./doc  -f ./website/SampleOutput.php -o HTML:Smarty:HandS

実行オプション:
-t: DOCの出力先
-d:DOCにする対象フォルダ
-o:出力形式の指定
-pp:—parseprivate。
※特にこのオプションは重要です。
このオプションがないとprivateのクラス変数を出力してくれないためです。

実行

Parsing time: 18 seconds
Conversion time: 41 seconds
Total Documentation Time: 59 seconds
done


出力完了。

指定したフォルダ(この場合はhttps://localhost/website/doc/) にドキュメント一式が生成されます。

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。