Download the PHP package console-helpers/parser-reflection without Composer
On this page you can find all versions of the php package console-helpers/parser-reflection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download console-helpers/parser-reflection
More information about console-helpers/parser-reflection
Files in console-helpers/parser-reflection
Package parser-reflection
Short Description Provides reflection information, based on raw source
License MIT
Informations about the package parser-reflection
Parser Reflection API Library
๐ Static Code Analysis Meets Reflection
Parser Reflection API brings the power of PHP's Reflection API to static code analysis. Built on top of nikic/php-parser, this library lets you introspect classes, interfaces, traits, enums, methods, properties, functions and constants without ever loading them into memory.
โจ Key Features
๐ง Pure AST-Based Reflection
Forget autoloading. This library parses your PHP source files directly into an Abstract Syntax Tree (AST) and extracts reflection data from the syntax itself โ no include, no require, no side effects. Analyze classes without bootstrapping your entire application. Perfect for static analyzers, code generators, documentation tools, and IDE plugins.
Why Use It?
- ๐ Source code analysis โ inspect structure without executing anything
- ๐งช Safe introspection โ avoid triggering constructors or static initializers
- ๐ Drop-in compatible โ extends native
\ReflectionClass,\ReflectionMethod,\ReflectionEnum, etc. - ๐ Modern PHP support โ enums, attributes (incl.
IS_INSTANCEOFfiltering), first-class callables, PHP 8.4 property hooks and lazy objects,const-declared global constants
Installation
Library can be installed with Composer. Installation is quite easy:
Composer will install the library to your project's vendor/goaop/parser-reflection directory.
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.
If project uses a custom autoloader then you should follow the next steps:
- Create a new class that implements
\Go\ParserReflection\LocatorInterface - 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:
Or you can use an additional classes ReflectionFileNamespace to analyse a raw PHP files:
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)
\Go\ParserReflection\ReflectionClassasks 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
ComposerLocatorinstance 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, except methods that require object manipulation, such as invoke(), invokeArgs(), setAccessible(), etc. These methods will trigger the process of class loading and switching to the internal reflection.
The only exception is \Go\ParserReflection\ReflectionConstant: the native \ReflectionConstant class is declared as final, so this class mirrors its public API instead of extending it.