Revision: Fri, 31 May 2024 16:10:39 GMT
v1.0 – outdated
This version of the documentation is outdated. Consider upgrading your project to Spiral Framework 3.12
Edit this page

Tokenizer / Static Analysis

The Spiral Framework ships with convenient way to automatically analyze your application in order to pre-compile some of it's functions.

Tokenizer extension is currently based on legacy way of code analysis - php token which limits it's functionality in some aspects. Feel free to contribute to implement AST based reflections.


In order to make tokenizer locate classes and method/function invocation we have to register set of directories to be iterated, such operation can be done inside tokenizer config:

return [
     * Tokenizer will be performing class and invocation lookup in a following directories. Less
     * directories - faster Tokenizer will work.
    'directories' => [

        //Default set of spiral console commands
        directory('framework') . 'Commands/',

        //Needed to allow Translator locate i18n validation messages
        directory('framework') . 'Validation/',

        //External modules
        directory('libraries') . 'spiral/ide-helper/source/',
        directory('libraries') . 'spiral/scaffolder/source/',
     * Such paths are excluded from tokenization. You can use format compatible with Symfony Finder.
    'exclude'     => [

Directories and exclude patters can be specified in Symfony Finder format.

Performance Considerations

Please note that code analysis is very slow operation, do not execute it based on user requests but rather move it into console command.

Following components use Tokenizer:

  • ORM - automatic location of Record, RecordEntity and Repository models
  • ODM - automatic location of Document and DocumentEntity and Repository models
  • Console - automatic location of available commands
  • Translator - automatic location of used i18n strings