2017 © Pedro Peláez
 

library block

Parsing docblocks made easy

image

ilya/block

Parsing docblocks made easy

  • Saturday, June 14, 2014
  • by ilya.s
  • Repository
  • 1 Watchers
  • 2 Stars
  • 58 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Block

Build Status, (*1)

Block makes parsing PHP DocBlocks easier., (*2)

Simple, documented and fully tested. PHP 5.4 is required., (*3)

Installation

Using Composer: composer require "ilya/block:~1"., (*4)

Example

Imagine you have the following code:, (*5)

class Foo {

    /**
     * The Bar.
     *
     * @var integer
     */
    protected $bar;

    /**
     * The Baz.
     *
     * @var string
     */
    public $baz;

    /**
     * Do Amaze.
     *
     * @param string $amaze
     * @return void
     */
    private function wow($amaze)
    {

    }

}

First, instantiate Block, like so: $block = new Block\Block(new Foo);., (*6)

Now you can begin to inspect the docblocks using these 4 methods available., (*7)

  • Block\Comment property(string $name)
  • array properties(integer $filter)
  • Block\Comment method(string $name)
  • array methods(integer $filter)
  • Block\Comment reflector(Reflector $reflector)

Methods property and method will receive a name (as a string) and return an instance of Block\Comment. Methods properties and methods will receive an optional argument $filter and return an array of Block\Comment instances., (*8)

If you are wondering what that $filter thing is, take a look at the example:, (*9)

$block->methods(ReflectionMethod::IS_PUBLIC); // only fetch public methods

// only fetch private AND protected properties
$block->properties(ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PROTECTED);

Ok, so now that you have an instance (or many of them) of \Block\Comment, what kind of actions can you perform?, (*10)

  • convert the instance to a string: $comment->getComment(). Note that (string) $comment would work too!
  • split it into lines: $comment->getLines().

Let's review the second option., (*11)

Calling the getLines() method will return an array, each element of which is an instance of \Block\Line., (*12)

Here's what it offers:, (*13)

  • boolean isTag(void) - determine whether the line contains a tag: will be true for @param int $speed and false for My desc.
  • string getLine(void) - get the line itself, as a string, note that (string) $line would also work.
  • array tokenize(void) - split the line into "tokens" - e.g @param int $speed will be represented as ['@param', 'int', '$speed']. All white spaces are ignored.
  • string stripTag(void)

So that's it, hopefully you now can start to use Block in your projects., (*14)

License

Block is licensed under the MIT license., (*15)

The Versions

14/06 2014

dev-master

9999999-dev

Parsing docblocks made easy

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Ilya S

php documentation reflection docs parsing blocks docblocks

14/06 2014

1.5.0

1.5.0.0

Parsing docblocks made easy

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Ilya S

php documentation reflection docs parsing blocks docblocks

11/06 2014

1.4.0

1.4.0.0

Parsing docblocks made easy

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Ilya S

php documentation reflection docs parsing blocks docblocks

01/06 2014

1.3.1

1.3.1.0

Parsing docblocks made easy

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Ilya S

php documentation reflection docs parsing blocks docblocks

01/05 2014

1.3.0

1.3.0.0

Parsing docblocks made easy

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Ilya S

php documentation reflection docs parsing blocks docblocks

01/05 2014

1.2.0

1.2.0.0

Parsing docblocks made easy

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Ilya S

php documentation reflection docs parsing blocks docblocks

25/04 2014

1.1.0

1.1.0.0

Parsing docblocks made easy

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Ilya S

php documentation reflection docs parsing blocks docblocks

13/04 2014

1.0.1

1.0.1.0

Parsing docblocks made easy

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Ilya S

php documentation reflection docs parsing blocks docblocks

13/04 2014

1.0.0

1.0.0.0

Parsing docblocks made easy

  Sources   Download

MIT

The Development Requires

by Ilya S

php documentation reflection docs parsing blocks docblocks