PhpDocumentorのインストールと文字コード変更

PHP5にしてからPhpDocumentorをインストールしていなかったのでインストールしてみた。

pearを使ってインストール

pearを使ってインストールする。
もしかすると使用メモリが足りない場合があるかもしれない。その場合はmemory_limitを変更すること。参考は以下。

http://caspar.hazymoon.jp/php/phpDocumentor/

# /usr/local/bin/pear install --alldeps phpdocumentor
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
downloading PhpDocumentor-1.4.2.tgz ...
Starting to download PhpDocumentor-1.4.2.tgz (2,421,028 bytes)
..............................................................................done: 2,421,028 bytes
downloading XML_Beautifier-1.2.0.tgz ...
Starting to download XML_Beautifier-1.2.0.tgz (12,948 bytes)
...done: 12,948 bytes
downloading XML_Parser-1.3.2.tgz ...
Starting to download XML_Parser-1.3.2.tgz (16,260 bytes)
...done: 16,260 bytes
downloading XML_Util-1.2.1.tgz ...
Starting to download XML_Util-1.2.1.tgz (17,729 bytes)
...done: 17,729 bytes
install ok: channel://pear.php.net/PhpDocumentor-1.4.2
install ok: channel://pear.php.net/XML_Parser-1.3.2
install ok: channel://pear.php.net/XML_Util-1.2.1
install ok: channel://pear.php.net/XML_Beautifier-1.2.0
# /usr/local/bin/pear list
Installed packages, channel pear.php.net:
=========================================
Package          Version State
Archive_Tar      1.3.2   stable
Console_Getopt   1.2.3   stable
PEAR             1.7.1   stable
PhpDocumentor    1.4.2   stable
Structures_Graph 1.0.2   stable
XML_Beautifier   1.2.0   stable
XML_Parser       1.3.2   stable
XML_Util         1.2.1   stable
#

文字エンコーディングの修正

テンプレートの文字エンコーディング指定がiso-8859-1になっているので修正する。
以下のファイルのencoding=charset=の"iso-8859-1"部分をUTF-8に変更。

# cd /usr/local/lib/php/data/PhpDocumentor/phpDocumentor/Converters/HTML/frames/templates/default/templates
# vi blank.tpl
# vi header.tpl
# vi index.tpl
# vi top_frame.tpl

テスト

phoinfo.phpから"man"というディレクトリにframe使用のhtmlを作成する場合。

タイトル Test Docmentation
パッケージ名 PHP INFO
カテゴリ名 All
$ /usr/local/bin/phpdoc -f phpinfo.php -t man -ti "Test Docmentation" -dn "PHP INFO" -dc All

なお、ヘルプ表示は以下の通り。

$ /usr/local/bin/phpdoc --help

作成例

Makefileなんかにしておくと便利。

$ cat Makefile
#
# Makefile for document using PhpDocumentor
#
PHPDOC = /usr/local/bin/phpdoc
TITLE = Test Documentation
PACKAGE = PHP INFO
CATEGORY = All
TARGET = ./man
SRC =   phpinfo.php # config.php index.php ....
SRCLIST = `echo $(SRC) | sed -e 's/[    ]\{1,\}/,/g'`
RM = rm

all: $(TARGET)

$(TARGET): $(SRC)
        @echo Create $(TITLE)
        @$(PHPDOC) -f $(SRCLIST) -t $(TARGET) \
                -ti "$(TITLE)" -dn "$(PACKAGE)" -dc $(CATEGORY) >/dev/null 2>&1

clean:
        @$(RM) -fr $(TARGET)
$ make