2017 © Pedro PelĂĄez
 

library notoj

Annotation parser. Uses reflection and provides cache out of the box.

image

crodas/notoj

Annotation parser. Uses reflection and provides cache out of the box.

  • Thursday, March 22, 2018
  • by crodas
  • Repository
  • 5 Watchers
  • 38 Stars
  • 15,431 Installations
  • PHP
  • 19 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 52 Versions
  • 9 % Grown

The README.md

Notoj Build Status

Yet another annotation parser (DocBlocks). It's designed to be simple and intuitive. It extends the Reflection methods inside the Notoj namespace (ReflectionClass, RefletionProperties, ReflectionMethod so far), and adds the getAnnotations() method., (*1)

<?php
use Notoj\ReflectionClass;

/** @foo @bar */
class Foo {
}

$reflection = new ReflectionClass('Foo');
var_dump($reflection->getAnnotations());
 ```

The `getAnnotations()` returns an array, with a very simple array structure (`array("method" => "Foo", "args" 
=> NULL)`)

How to use it
-------------

Notoj supports works under two scenearios, `offline` and `online` parsing.

### Online

Online parsing means that you want to retrieve annotations from an object, class or function that exists at run time. To use you'd need to use Reflection classes from the Notoj namespace.

### Offline

Offline parsing means that you want to get annotations from a file or directory and you rather not include them to use the `online` API. Notoj provides the `Notoj\File` and `\Notoj\Dir` classes to do that. They both return `Annotations` object which behaves as an array of `Annotation` (the output the `online` API), plus with a few extra things such as the `file`, `line`.


#### File
```php
<?php
$parser = new \Notoj\File("/foo.php");
$parser->getAnnotations();

Dir

<?php
$parser = new \Notoj\Dir("/foo"); // The parser is recursive
$parser->setFilter(function($file) {
 return true;
});
$annotations = $parser->getAnnotations();
foreach ($annotations->get('Foo\Bar') as $annotations) {
   foreach ($annotations as $annotation) {
      var_dump(
          "found @Foo\Bar at " . $annotation['file'] 
          . ($annotation->isClass() ? ' on a class ' : ' on something else other than a class')
      );
   }
}

Annotation object

It is the output object that represents an annotation. It is important that you notice that it does represents the annotations in a object, class or function and not a single annotation., (*2)

It provides ->get($tag) and ->has($tag) filters that helps processing the object., (*3)

<?php
// check if there is a @Foo
if (!$annotation->has('Foo')) {
  throw new \RuntimeException("We were expecting a Foo annotation tag");
}

// ensure that *every* @Foo has at least some argument
foreach ($annotation->get('Foo') as $ann) {
   if (empty($ann['args'])) {
      throw new \RuntimeException("we were expecting arguments");
   }
}

foreach ($annotation as $ann) {
    // get *All* iterations
}

Annotations object

It is an object that behaves like an array of Annotation object. Provides a very simple filter ->get($name) and ->has($name)., (*4)

Format

<?php
/** @Foo */
/** @Foo("some") */
/** @Foo some other strings */
/** @Foo(some_label="something here") */
/** @Foo({some: "array here", arr:[1,2,3]}) */
/** @Foo(some_label={some: "array here", arr:[1,2,3]}) */

Warning: Notoj will do its best effort to parse broken annotations, but if there is an error it will fail silently. Also, in the @foo bar foobar format whitespaces are ignored., (*5)

Caching support

Notoj supports caching that will help the Notoj's engine to avoid parsing over and over the same string. The cache will be invalidated automatically., (*6)

To enable this feature you need to specify which file should be used to save the cache, Notoj will do the rest :-)., (*7)

Notoj::enableCache("/tmp/annotations.php");

Todo

  • Cache for offline parsing

Feel free to email fork and submit pull requests or write me crodas@php.net, (*8)

The Versions

22/03 2018

dev-develop

dev-develop

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

The Development Requires

by CĂ©sar D. Rodas

22/03 2018

dev-master

9999999-dev

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

The Development Requires

by CĂ©sar D. Rodas

22/03 2018

v1.6.1

1.6.1.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

The Development Requires

by CĂ©sar D. Rodas

22/03 2018

v1.6.0

1.6.0.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

The Development Requires

by CĂ©sar D. Rodas

29/03 2017

v1.5.2

1.5.2.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

29/03 2017

v1.5.1

1.5.1.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

16/11 2016

v1.4.2

1.4.2.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

The Development Requires

by CĂ©sar D. Rodas

10/11 2016

v1.4.1

1.4.1.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

The Development Requires

by CĂ©sar D. Rodas

10/11 2016

dev-feature/better-cache

dev-feature/better-cache

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

The Development Requires

by CĂ©sar D. Rodas

04/04 2016

v1.3.3

1.3.3.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

01/04 2016

v1.3.2

1.3.2.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

31/03 2016

v1.3.1

1.3.1.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

05/01 2016

v1.2.2

1.2.2.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

29/12 2015

v1.2.1

1.2.1.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

23/12 2015

v1.1.1

1.1.1.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

25/08 2015

v1.0.9

1.0.9.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

08/08 2015

v1.0.8

1.0.8.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

08/08 2015

v1.0.7

1.0.7.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

31/07 2015

v1.0.6

1.0.6.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

03/06 2015

v1.0.5

1.0.5.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

23/05 2015

v1.0.4

1.0.4.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

21/03 2015

v1.0.3

1.0.3.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

13/03 2015

v1.0.2

1.0.2.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

26/01 2015

v1.0.1

1.0.1.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

26/01 2015

v1.0.0

1.0.0.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

24/01 2015

dev-master-2-docs

dev-master-2-docs

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

07/01 2015

0.2.0.x-dev

0.2.0.9999999-dev

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

06/01 2015

v0.1.22

0.1.22.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

26/10 2014

dev-feature/quick-annotation

dev-feature/quick-annotation

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

26/10 2014

v0.1.21

0.1.21.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

27/09 2014

v0.1.20

0.1.20.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

05/09 2014

v0.1.19

0.1.19.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

05/09 2014

v0.1.18

0.1.18.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

03/09 2014

v0.1.17

0.1.17.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

31/05 2014

v0.1.16

0.1.16.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

06/05 2014

v0.1.15

0.1.15.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

26/04 2014

v0.1.14

0.1.14.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

07/01 2014

v0.1.13

0.1.13.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

29/12 2013

v0.1.12

0.1.12.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

28/12 2013

v0.1.11

0.1.11.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

25/12 2013

v0.1.10

0.1.10.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

15/11 2013

v0.1.9

0.1.9.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

15/11 2013

v0.1.8

0.1.8.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

24/10 2013

v0.1.7

0.1.7.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

24/10 2013

dev-feature/crodas/class-info

dev-feature/crodas/class-info

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

 

by CĂ©sar D. Rodas

21/10 2013

v0.1.6

0.1.6.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

  • php >=5.3.0

 

by CĂ©sar D. Rodas

08/08 2013

v0.1.5

0.1.5.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

  • php >=5.3.0

 

by CĂ©sar D. Rodas

08/08 2013

v0.1.4

0.1.4.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

  • php >=5.3.0

 

by CĂ©sar D. Rodas

08/08 2013

v0.1.2

0.1.2.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

  • php >=5.3.0

 

by CĂ©sar D. Rodas

07/08 2013

v0.1.1

0.1.1.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

  • php >=5.3.0

 

by CĂ©sar D. Rodas

07/08 2013

v0.1.0

0.1.0.0

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

BSD-4-Clause

The Requires

  • php >=5.3.0

 

by CĂ©sar D. Rodas

13/08 2012

dev-annotation-class-loader

dev-annotation-class-loader

Annotation parser. Uses reflection and provides cache out of the box.

  Sources   Download

The Requires

  • php >=5.3.0

 

by CĂ©sar D. Rodas