phpdocumentationparsingdocblocks

Are there any PHP DocBlock parser tools available?


I would like to build some smaller scale but hightly customized documentation sites for a few projects. PhpDocumentor is pretty great but it is very heavy. I thought about trying to tweak the templates for that but after spending only a couple of minutes looking into it I decided that it would be too much work.

Ideally I'd like to see something to which I could pass a bunch of files and have it return all of the files, classes and properties and methods, along with their meta data, so that I could build out some simple templates based on the data.

Are there any DocBlock parser-only projects that will help me in this task, or am I stuck reinventing that wheel?


Solution

  • You can do this easily yourself with the Reflection API:

    /**
     * This is an Example class
     */
    class Example
    {
        /**
         * This is an example function
         */
        public function fn() 
        {
            // void
        }
    }
    
    $reflector = new ReflectionClass('Example');
    
    // to get the Class DocBlock
    echo $reflector->getDocComment()
    
    // to get the Method DocBlock
    $reflector->getMethod('fn')->getDocComment();
    

    See this tutorial: http://www.phpriot.com/articles/reflection-api

    There is also a PEAR package that can parse DocBlocks.