2017 © Pedro Peláez
 

library parser-reflection

Provides reflection information, based on raw source

image

goaop/parser-reflection

Provides reflection information, based on raw source

  • Monday, March 19, 2018
  • by lisachenko
  • Repository
  • 7 Watchers
  • 57 Stars
  • 501,645 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 20 Forks
  • 23 Open issues
  • 14 Versions
  • 14 % Grown

The README.md

Parser Reflection API Library

This library is deprecated. Please use BetterReflection., (*1)

Parser Reflection API library provides a set of classes that extend original internal Reflection classes, but powered by PHP-Parser library thus allowing to create a reflection instance without loading classes into the memory., (*2)

This library can be used for analysing the source code; for automatic proxy creation and much more., (*3)

Build Status Code Coverage Total Downloads Daily Downloads Scrutinizer Code Quality PHP Version License, (*4)

Installation

Library can be installed with Composer. Installation is quite easy:, (*5)

$ composer require goaop/parser-reflection

Composer will install the library to your project's vendor/goaop/parser-reflection directory., (*6)

Usage

Initialization

Prior to the first use library can be optionally initialized. If you use Composer for installing packages and loading classes, then you shouldn't worry about initialization, library will be initialized automatically., (*7)

If project uses a custom autoloader then you should follow the next steps:, (*8)

  1. Create a new class that implements \Go\ParserReflection\LocatorInterface
  2. Create an instance of that class and pass it to the ReflectionEngine::init() method for initial configuration

Reflecting concrete classes/methods/properties without loading them

Just use Go\ParserReflection package reflection classes like traditional ones:, (*9)

$parsedClass = new \Go\ParserReflection\ReflectionClass(SomeClass::class);
var_dump($parsedClass->getMethods());

$parsedMethod = new \Go\ParserReflection\ReflectionMethod(SomeClass::class, 'someMethod');
echo (string)$parsedMethod;

Or you can use an additional classes [ReflectionFile]0 and ReflectionFileNamespace to analyse a raw PHP files:, (*10)

$parsedFile     = new \Go\ParserReflection\ReflectionFile('SomeClass.php');
$fileNameSpaces = $parsedFile->getFileNamespaces();
// We can iterate over namespaces in the file
foreach ($fileNameSpaces as $namespace) {
    $classes = $namespace->getClasses();
    // Iterate over the classes in the namespace
    foreach ($classes as $class) {
        echo "Found class: ", $class->getName(), PHP_EOL;
        // Now let's show all methods in the class
        foreach ($class->getMethods() as $method) {
            echo "Found class method: ", $class->getName(), '::', $method->getName(), PHP_EOL;
        }

        // ...all properties in the class
        foreach ($class->getProperties() as $property) {
            echo "Found class property: ", $class->getName(), '->', $property->getName(), PHP_EOL;
        }
    }
}

How it works?

To understand how library works let's look at what happens during the call to the new \Go\ParserReflection\ReflectionClass(SomeClass::class), (*11)

  • \Go\ParserReflection\ReflectionClass asks reflection engine to give an AST node for the given class name
  • Reflection engine asks a locator to locate a filename for the given class
  • ComposerLocator instance asks the Composer to find a filename for the given class and returns this result back to the reflection engine
  • Reflection engine loads the content of file and passes it to the PHP-Parser for tokenization and processing
  • PHP-Parser returns an AST (Abstract Syntax Tree)
  • Reflection engine then analyse this AST to extract specific nodes and wrap them into corresponding reflection classes.

Compatibility

All parser reflection classes extend PHP internal reflection classes, this means that you can use \Go\ParserReflection\ReflectionClass instance in any place that asks for \ReflectionClass instance. All reflection methods should be compatible with original ones, providing an except methods that requires object manipulation, such as invoke(), invokeArgs(), setAccessible(), etc. These methods will trigger the process of class loading and switching to the internal reflection., (*12)

The Versions

19/03 2018

dev-master

9999999-dev

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

19/03 2018

1.4.1

1.4.1.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

03/09 2017

1.4.0

1.4.0.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

27/08 2017

1.3.0

1.3.0.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

27/06 2017

1.2.1

1.2.1.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

09/04 2017

dev-fix/is-subclass-of

dev-fix/is-subclass-of

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

29/12 2016

1.2.0

1.2.0.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

25/09 2016

1.1.0

1.1.0.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

27/02 2016

1.0.2

1.0.2.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

21/02 2016

1.0.1

1.0.1.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

15/02 2016

1.0.0

1.0.0.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

26/12 2015

1.0.0-alpha

1.0.0.0-alpha

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

26/12 2015

0.6.0

0.6.0.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko

22/11 2015

0.5.0

0.5.0.0

Provides reflection information, based on raw source

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Lisachenko