views:

69

answers:

2

Hi folks,

I'm looking for some method of converting a PHP Docblock (as used for generating documentation by tools like Doxygen) into a structure I can inspect in PHP.

For example, I want to parse the following lines:


    /**
     * Multiply two values
     * @CHECKME
     *
     * @author someone
     * @created eons ago
     *
     * @param integer $x
     * @param integer $x
     *
     * @return integer
     */
    function multiply($x, $y)
    {
        return $x * $y;
    }

Into something similar to:


    array(
         'author'  => 'someone'
        ,'created' => 'eons ago'
        ,'param'   => array(
                          'integer $x'
                         ,'integer $y'
                      )
        ,'_flags'  => array(
                         '@CHECKME'
                      )
    );

I explicitly cannot use PEAR or any such library, it has to be relatively standalone. Any given solution that is better than using a bunch of regexes after stripping away comment outline would be awesome.

+1  A: 

I wonder if you couldn't just use the phpdocumentor classes. They already parse the data. I suspect you could write your own interim parser to process a file but then handle the raw objects in any way you want.

Inkspeak
I've been unable to get into any source for phpDocumentor for the last couple hours, but my assumptions based on the website/faq are that it is php4 code that depends on PEAR (need PEAR to install it). Using it would not be less work than writing it myself by the look of things. (I could be wrong, unable to verify atm)
Kris
The classes are available as *.inc files within the phpDocumentor directory upon download. I'm not sure if you saw that or not.
Inkspeak
Yes I did but by the time I have familiarized mysql with the old fashioned style and structure I can have written my own implementation that follows my actual spec and i'd still have to re-qrite the php4 code by that time. Standalone != complete project
Kris
A: 

PHPDocumentor IS a standalone docblock parser.

powtac
I just downloaded a zip and looked at the source, but phpDocumentors code is terrible for my use case. It will take days to rework that instead of hours to roll my own. I need one or two classes, not an intermingled project with dependencies all over the place, and certainly no php4 code. I might be able to glean something from it if i run something through it in an xdebug session, but after seeing the code I still think its unusable.
Kris