Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Tokenizer Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

The package is typically used in console commands or build tools for code introspection. Common patterns include:

  • Dependency Registration: Dynamically register services by scanning for classes implementing a common interface (e.g., CommandInterface).
  • Code Quality Checks: Build custom analyzers to enforce architectural rules (e.g., ensure all entities extend a base model).
  • Metadata Harvesting: Extract annotations or attributes across many classes at build time for caching or documentation generation. Workflows often integrate with Symfony Console, running as a CLI tool. Use TokenizedFile::getTokens() for lower-level token access when custom logic is needed beyond the provided filters.

Gotchas and Tips

  • PHP Version Constraints: Supports PHP 7.2–7.4; incompatible with PHP 8+ due to reliance on deprecated token_get_all() parsing (no AST). Expect issues with modern syntax like union types or attributes.
  • Performance: Scans are file-system heavy—cache results if reused. Consider limiting scope via Tokenizer::$excludedDirectories.
  • Incomplete Parsing: May miss classes in eval() or dynamically generated code; strictly static analysis only.
  • Extension Points: Extend Tokenizer or TokenizedFile to customize scanning rules or add class filters (e.g., skip tests).
  • Alternatives: For new projects, consider 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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle