Generating PHP documentation from NetBeans 6.5
By Petr on Nov 05, 2008
NetBeans 6.5 doesn't have direct support for generating PHP documentation. Here is a trick how to do it. Basically I use a new Run Configuration that calls a small script to generate the documentation. I did this on my Ubuntu machine, but Windows users should be able to reuse the steps.
At first I downloaded the PHPDocumentor itself from the project pages, unzipped the zip file and change the rights of phpdoc to be executable.
For the next step I created a new bash script which I call from NetBeans. You can write the script directly in NetBeans. NetBeans PHP distro includes very simple syntax coloring support for bash script and bat files as well. The picture below displays NetBeans PHP RC2, showing my phpdocNB.sh script that I use for generating the documentation.
The text form of the script:
#! /bin/bash # Script for generatig php documentation from NetBeans through run configuration PATH_TO_PHP_DOCUMENTOR=/space/php/phpdocumentor/PhpDocumentor $PATH_TO_PHP_DOCUMENTOR/phpdoc -d $2 -t $3 echo "Generating PHP Documentation finished ..." firefox $3/index.html
As you can see the script is very simple. If you want to use it, you should just change the value of PATH_TO_PHPDOCUMENTOR variable to pick up the phpdoc script from your location. Through the -d parameter you define which directory will be parsed (and subdirectories) and -t parameter says in which directory the PHPDocumentor should create the documentation files. When the generation of the documentation is finished than the result is opened in new Firefox tab to check the result.
Now, when the script is done, I need to call it from NetBeans. As I have mentioned we can use for this new Run Configuration. There are three ways how to display Project Properties dialog where you can create it. You can select the project node and in the context menu over this node invoke Properties item or from main File menu choose Project Properties item or in the main tool bar there is combobox with already existing configurations and the last item in the combo box is Configure... item. The combo box in the main tool bar is a way how to quickly switch between configurations.
So in the Project Properties dialog click on the Run Configuration category and create new configuration through the New... button. I have named the configuration PHPDocumentor. In the Run As combo box select Script (run in command line) item. Uncheck Use default PHP Interpreter and browse the created script. As the first argument put the path of your project sources. You can copy the path from the Source category panel, Source Folder text field. As the second parameter put a path, where you want to generate the documentation. The folder doesn't have to exist, the PHPDocumentor will create it. The picture below shows my PHPDocumentor configuration.
NetBeans will put for the script as the first argument the Index File, when you run project with this configuration or the file for which you invoke Run Single File action. This parameter is in my script simply ignored and always the documentation is generated for all sources.
Now when I choose the PHPDocumentor configuration in the combo box in the main tool bar and run the project, then the documentation is generated and the result is opened in new Firefox tab.
You can improve the script and add more parameters, it's all up to you. I know that this is not the ideal support of PHPDocumentor, but for the next verion I want to make the real integration. If a Windows user out there will write the bat file, could you please attach the file in a comment, and I will alter this post.