Today I needed to generate source code documentation for a webservice APIs we are in coding. One of the guys in the office suggested I take a look at Zend_Reflection. It turns out its quite simple to write PHP code to parse source files and extract the documentation from them. I took a little time to write this sample program.
This program is quite simple: it has a single class called TestClass with one method: addIntegers(). Below this class I wrote a little code which parses the file and then outputs the information. You can use this and a templating system to generate doc. I used it to write the documentation so that we can easily add it to our Wiki.
The script I wrote parses the documentation style used in Zend Framework. Here’s a sample class:
/**
* This is a sample test class.
*
* This class has only one method: addIntegers() which adds
* two integers. Its a sample class for our test.
*
*/
class TestClass
{
/**
* This method adds two integers.
*
* This method adds the two given integers and returns
* its sum. If only one integer is given it sums zero.
*
* @param int $number1 The first integer
* @param int $number2 The second integer
* @return int The sum of $number1 and $number2.
*
*/
public function addIntegers( $number1, $number2 = 0 ) {
return $number1 + $number2;
}
}
Read the rest of the post to see how to easily parse this code…
Continue reading “Using Zend_Reflection to generate API docs” »

