2017 © Pedro Peláez
 

library docblock

A simple library for parsing PHP DocBlock comments

image

dannykopping/docblock

A simple library for parsing PHP DocBlock comments

  • Monday, April 21, 2014
  • by dannykopping
  • Repository
  • 2 Watchers
  • 20 Stars
  • 1,588 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

PHP DocBlock Lite

Build Status Scrutinizer Quality Score, (*1)

WTF is a DocBlock?

A DocBlock is a block comment in PHP (with optional annotations):, (*2)


/** * Optional DocBlock comment * * @annotation I'm an annotation! */

Installation

Download or clone the repository and add a require_once statement to include the Parser class., (*3)


Usage

phpDBL (PHP DocBlock Lite) uses the Reflection API (available from PHP 5) to allow you to retrieve the DocBlock comments. phpDBL will then inspect all the methods available in any given class and examine their DocBlocks., (*4)


analyze("MyClassName"); $methods = $d->getMethods(); print_r($methods); ?>

You can also retrieve a list of given annotations:, (*5)


analyze("TestClass"); $methods = $d->getMethods(); foreach($methods as $method) { $annotations = $method->getAnnotations(array("param")); foreach ($annotations as $annotation) { echo $annotation->getMethod()->name . "\n"; echo $annotation->name . "\n"; echo print_r($annotation->values, true) . "\n"; } } class TestClass { /** * This is the DocBlock description * @param $data The data to be passed in */ public function test($data) { } } ?>

Which will produce:, (*6)


test @param Array ( [0] => $data [1] => The data to be passed in )

Full Example

setAllowInherited(true);
    $d->setMethodFilter(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED);
    $d->analyze(array("TestClass", "Parser"));

    $classes = $d->getClasses();

    foreach ($classes as $class)
    {
        echo "Class: " . $class->name . "\n";

        $methods = $class->getMethods();
        foreach ($methods as $method)
        {
            $annotations = $method->getAnnotations(array("param", "author"));

            echo "Method: " . $method->getClass()->name . "::" . $method->name . "\n";
            echo "Description: " . $method->description . "\n";

            if (empty($annotations))
                continue;

            foreach ($annotations as $annotation)
            {
                echo "\tAnnotation: " . $annotation->name . "\n";
                echo "\tValues: " . print_r($annotation->values, true) . "\n";
            }

            echo str_repeat("-", 50) . "\n";
        }
    }

    class BaseClass
    {
        /**
         * Test function 1
         */
        public function testFunc1()
        {

        }

        /**
         * Test function 2
         */
        protected function testFunc2()
        {

        }
    }

    class TestClass extends BaseClass
    {
        /**
         * This is the DocBlock description
         * @param $data  The data to be passed in
         */
        public function test($data)
        {
        }

        /**
         * This is another DocBlock description
         * @param $data  The data to be passed in
         * @author    Danny Kopping
         */
        protected function test2($data)
        {
        }
    }

?>

Contact

Feel free to suggest feature requests by creating an "Issue" or by forking the repo, making the changes yourself and sending me a pull request., (*7)

The Versions

21/04 2014

dev-master

9999999-dev https://github.com/dannykopping/PHPDocBlock-lite

A simple library for parsing PHP DocBlock comments

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser docblock reflection parse

16/04 2014

0.5.2

0.5.2.0 https://github.com/dannykopping/PHPDocBlock-lite

A simple library for parsing PHP DocBlock comments

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser docblock reflection parse

16/04 2014

0.5.1

0.5.1.0 https://github.com/dannykopping/PHPDocBlock-lite

A simple library for parsing PHP DocBlock comments

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser docblock reflection parse

07/06 2013

0.5

0.5.0.0 https://github.com/dannykopping/PHPDocBlock-lite

A simple library for parsing PHP DocBlock comments

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser docblock reflection parse

07/06 2013

0.4

0.4.0.0 https://github.com/dannykopping/PHPDocBlock-lite

A simple library for parsing PHP DocBlock comments

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser docblock reflection parse

21/10 2012

0.3

0.3.0.0 https://github.com/dannykopping/PHPDocBlock-lite

A simple library for parsing PHP DocBlock comments

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser docblock reflection parse

15/10 2012

0.2

0.2.0.0 https://github.com/dannykopping/PHPDocBlock-lite

A simple library for parsing PHP DocBlock comments

  Sources   Download

The Requires

  • php >=5.3.0

 

parser docblock reflection parse

05/10 2012

0.1

0.1.0.0 https://github.com/dannykopping/PHPDocBlock-lite

A simple library for parsing PHP DocBlock comments

  Sources   Download

The Requires

  • php >=5.3.0

 

parser docblock reflection parse