2017 © Pedro Peláez
 

library reflection

Nette Reflection: docblock annotations parser and common reflection classes

image

nette/reflection

Nette Reflection: docblock annotations parser and common reflection classes

  • Friday, June 22, 2018
  • by david@grudl.com
  • Repository
  • 33 Watchers
  • 73 Stars
  • 1,642,911 Installations
  • PHP
  • 145 Dependents
  • 2 Suggesters
  • 12 Forks
  • 0 Open issues
  • 12 Versions
  • 5 % Grown

The README.md

Nette PHP Reflection

Downloads this Month Build Status Coverage Status Latest Stable Version License, (*1)

Install it using Composer:, (*2)

composer require nette/reflection

The last stable release requires PHP version 5.6 or newer (is compatible with PHP 7.0 and 7.1)., (*3)

If you like Nette, please make a donation now. Thank you!, (*4)

If you need to find every information about any class, reflection is the right tool to do it. You can easily find out which methods does any class have, what parameters do those methods accept, etc., (*5)

// getting PDO class reflection
$classReflection = new Nette\Reflection\ClassType('PDO');

// getting PDO::query method reflection
$methodReflection = new Nette\Reflection\Method('PDO', 'query');

Annotations

Reflection has really a lot to do with annotations. The annotations are written into phpDoc comments (two opening asterisks are mandatory!) and start with @. You can annotate classes, variables and methods:, (*6)

/**
 * @author John Doe
 * @author Tomas Marny
 * @secured
 */
class FooClass
{
    /** @Persistent */
    public $foo;

    /** @User(loggedIn, role=Admin) */
    public function bar() {}
}

In the code there are these annotations:, (*7)

  • @author John Doe - string, contains text value 'John Doe'
  • @Persistent - boolean, its presence means true
  • @User(loggedIn, role=Admin) - contains associative array('loggedIn', 'role' => 'Admin')

The existence of a class annotation can be checked via hasAnnotation() method:, (*8)

$fooReflection = new Nette\Reflection\ClassType('FooClass');
$fooReflection->hasAnnotation('author'); // returns true
$fooReflection->hasAnnotation('copyright'); // returns false

Values can be acquired with getAnnotation():, (*9)

$fooReflection->getAnnotation('author'); // returns string 'Tomas Marny'

$fooReflection->getMethod('bar')->getAnnotation('User');
// returns array('loggedIn', 'role' => 'Admin')

.[caution] Previous definitions are overwritten with the latter ones, sou you will always get the last one., (*10)

All annotations can be obtained with getAnnotations():, (*11)

array(3) {
    "author" => array(2) {
        0 => string(8) "John Doe"
        1 => string(11) "Tomas Marny"
    }
    "secured" => array(1) {
        0 => bool(true)
    }
}

The Versions

22/06 2018

dev-master

9999999-dev https://nette.org

Nette Reflection: docblock annotations parser and common reflection classes

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

reflection nette annotation

16/07 2017

v2.3.x-dev

2.3.9999999.9999999-dev https://nette.org

Nette Reflection: docblock annotations parser and common reflection classes

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

reflection nette annotation

11/07 2017

v2.4.2

2.4.2.0 https://nette.org

Nette Reflection: docblock annotations parser and common reflection classes

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

reflection nette annotation

10/01 2017

v2.4.1

2.4.1.0 https://nette.org

Nette PHP Reflection Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

17/05 2016

v2.4.0

2.4.0.0 https://nette.org

Nette PHP Reflection Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

12/03 2016

v2.3.2

2.3.2.0 https://nette.org

Nette PHP Reflection Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

06/02 2016

2.2.x-dev

2.2.9999999.9999999-dev https://nette.org

Nette PHP Reflection Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

19/07 2015

v2.2.2

2.2.2.0 http://nette.org

Nette PHP Reflection Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

11/07 2015

v2.3.1

2.3.1.0 http://nette.org

Nette PHP Reflection Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

16/02 2015

v2.3.0

2.3.0.0 http://nette.org

Nette PHP Reflection Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

15/11 2014

v2.2.1

2.2.1.0 http://nette.org

Nette PHP Reflection Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

24/06 2014

v2.2.0

2.2.0.0 http://nette.org

Nette PHP Reflection Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires