spiral/tokenizer
Fast PHP tokenizer for discovering classes, interfaces, traits, and functions without loading files. Scans directories, parses source code, and builds a registry for runtime reflection, DI containers, and framework bootstrapping—lightweight and cache-friendly.
Start by installing the package via Composer (composer require spiral/tokenizer). Despite its low star count and outdated last release (2019), it remains useful in legacy Spiral Framework projects for static analysis. Its primary use case is scanning codebase files to locate classes implementing a given interface, extending a parent class, or using a specific trait—without executing PHP code. Begin by instantiating the Tokenizer class, providing the root directory to scan, then call getClassesByInterface(), getClassesByParent(), or getClassesByTrait() with the fully qualified name.
The package is typically used in console commands or build tools for code introspection. Common patterns include:
CommandInterface).TokenizedFile::getTokens() for lower-level token access when custom logic is needed beyond the provided filters.token_get_all() parsing (no AST). Expect issues with modern syntax like union types or attributes.Tokenizer::$excludedDirectories.eval() or dynamically generated code; strictly static analysis only.Tokenizer or TokenizedFile to customize scanning rules or add class filters (e.g., skip tests).nikic/php-parser for robust AST-based analysis or Spiral’s newer spiral/annotated in modern frameworks. Given the age of this package, treat it as legacy tooling—great for maintaining older Spiral apps, but avoid in greenfield development.How can I help you explore Laravel packages today?