Do You PHP?    
Search Engine Optimization  php5 powerd  Valid XHTML 1.0!  Valid CSS!  このサイトのはてなブックマーク数 



last updated
2005/05/25

counter hits
since 1999/11/06


PHPXref - クロスリファレンスドキュメントの自動生成

過去に書いたソースや他の方が書いたソースで、関数や定数の定義などを探すことがあると思いますが、みなさんはどうされてますか?grep?それもありですね(^-^; ただ、ブラウザからリンクを辿っていくと、関数や定数の定義、また、それを使っている場所を簡単に探すことができたら、メンテナンスがより簡単になると思いませんか?(私だけかも。。。)

CではCross-Referencing Linux、JavaではJakarta ProjectのMaven(機能の1つのようです)などがありますが、PHPでそれに相当するのがPHPXrefです。

PHPXrefはPerlスクリプトで、SourceForgeから入手することができます。実際にどのような画面が作成されるのかも確認できます。2004/10/31時点で最新はphpxref-0.6で、PHP5の基本的な文法にも対応しているようです(2年前にこのサイトで紹介したときは、1年以上更新されていなかったのですが。。。)。

今回は、以前PHPDocの対象にしたXSLTラッパークラスに対してクロスリファレンスを作成してみます。

導入の方法は非常に簡単で、入手したtar.gzを適当なディレクトリに展開します。次に、展開したディレクトリにあるphpxref.cfgを編集します。今回修正した個所は、以下の2カ所だけです。

  • SOURCE:クロスリファレンスを作成するPHPソースのパス
  • OUTPUT:クロスリファレンスの出力パス
●phpxref.cfg
                       :
     6
     7  # The base directory containing all of your PHP code to be indexed
     8  # This could just be a directory containing symlinks to the real directories
     9  #SOURCE=C:\webserver\sites\www.myhost.com\htdocs
    10  #SOURCE=source
    11  SOURCE=/path/to/jp/ne/hi_ho/pat/dimension/xml/xslt
    12
    13  # The directory in which you'd like the output to be written
    14  #OUTPUT=C:\phpxref\output
    15  #OUTPUT=output
    16  OUTPUT=output/xref_0_6
    17
                       :
  

そして、phpxref.plを実行します。Windowsの場合、用意されているphpxref.batを実行します。

●phpxref.plの実行
$ ./phpxref.pl
PHPXref 0.6
(c) Gareth Watts 2004

Processing Unnamed Project v0.00...
Source.............: /path/to/jp/ne/hi_ho/pat/dimension/xml/xslt
Target.............: /path/to/phpxref-0.6/output/xref_0_6
Scanning Tree......: OK - 9 files to process
Pass One...........: 0%..100%
Generating Output..: 0%..100%
Variable references: 0%..70%..100%
Function references: 0%..10%..20%..30%..40%..50%..60%..70%..80%..90%..100%
Class references...: 0%..100%
Constant references: 0%..100%
Table references...:

Some values were referenced in require and include statements
for which no value could be found in the configuration file so cross-referencingmay be incomplete:
Unknown constant names (ref count): CLASSPATH_XSLT (4)

Summary statistics:
Files Scanned: 9 containing 464 lines
17 variable names in 13 definitions and 124 references.
20 function/method names in 23 definitions and 25 references.
3 constant names in 4 definitions and 14 references.
9 class names in 9 definitions and 10 references.
0 table names in 0 references.

Local front page URL: file:///path/to/phpxref-0.6/output/xref_0_6/index.html

Done.
$ 

こうして作成したドキュメントはこのような感じです。2年前に使ったphpxref-0.2から格段にいい感じになっています。ちなみに、phpxref-0.2ではこのような感じでした。phpxref-0.6では、特にSourceViewでJavaScriptやDynamic HTMLなどをうまく使っていて、

  • ある変数の上にマウスカーソルを持っていくと、同名の変数が全て反転表示される
  • 自作関数やPHP関数、定数の上にマウスカーソルを持っていくと、別レイヤで定義元や参照先が表示され、さらにそこへのリンクが表示されている

といったところがマルです。

ただし、PHPが提供している関数名の定義が外部ファイルになっていて、最新ものもに対応させようとすると自分でメンテナンスする必要があるのは変わらずです(まあ、しょうがないんですが。。。)。

プロジェクトなどの引継用資料とか、PEARをハックしてみたい方に良いんではないでしょうか?お手軽に作成できますし。。。



About This Site |  Privacy Policy |  Contact
Copyright © 1999 - 2005 by Hideyuki SHIMOOKA all rights reserved.