andrewsville/php-token-reflection
PHP library for reflecting and analyzing PHP token streams. Parse source code into tokens and inspect structures like classes, functions, namespaces, and docblocks—useful for static analysis, code generation, and tooling without executing the code.
Begin by installing via Composer: composer require andrewsville/php-token-reflection. Despite being archived, it remains usable for static inspection of PHP source without execution. Initialize the broker and parse a file:
$broker = new TokenReflection\Broker();
$broker->addCode(file_get_contents('src/MyService.php'));
$class = $broker->getClass('App\MyService');
First use case: Extract public method names and their docblock short descriptions for generating API documentation stubs or scaffolding service introspection.
TokenReflection\Broker) to enforce internal conventions—e.g., require @deprecated tags on methods with specific names.@method annotations referencing removed methods or deprecated patterns (e.g., mysql_* calls in docblocks).chokidar CLI or Laravel’s artisan make:listener --watch) by calling clearCache() after addCode() to refresh reflection state incrementally.ide-php or intelephense plugins to补充 missing docblocks or improve autocomplete fidelity.int|string), and attributes (#[Route(...)]) are not reliably parsed—verify against your PHP version; many modern syntax features will throw or misinterpret tokens.use App\Models\User → App\Models\User). You must manually resolve using getNamespaceAliases() and getImports().opcache.file_cache. Always call $broker->clearCache() before re-parsing modified files in long-running processes (e.g., console commands).self::MAX_RETRY) are exposed as strings—no runtime value resolution. Use ReflectionClass::getConstant() only works for declared constants, not values.nikic/php-parser + custom AST visitors for better maintainability and PHP version support.How can I help you explore Laravel packages today?