ray / compiler
A dependency injection compiler for Ray.Di
Installs: 895 795
Dependents: 4
Suggesters: 0
Security: 0
Stars: 5
Watchers: 4
Forks: 3
Open Issues: 2
Requires
- php: ^7.2 || ^8.0
- doctrine/annotations: ^1.12 || ^2.0
- doctrine/cache: ^1.10 || ^2.1
- koriym/attributes: ^1.0
- koriym/null-object: ^1.0
- koriym/param-reader: ^1.0
- koriym/printo: ^1.0
- nikic/php-parser: ^4.5 || ^5.0
- ray/aop: ^2.14
Requires (Dev)
- ext-pdo: *
- bamarni/composer-bin-plugin: ^1.4
- phpunit/phpunit: ^8.5.24 || ^9.5
- ray/di: ^2.16
- 1.x-dev
- 1.106
- 1.10.6
- 1.10.5
- 1.10.4
- 1.10.3
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.7
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.3.0
- 0.2.0
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-wakeup-try-coverage100-but-failed
- dev-fiber
- dev-log_bindings
- dev-compile-log
- dev-construct
- dev-php8
This package is auto-updated.
Last update: 2024-10-21 02:16:28 UTC
README
Dependency Injection Compiler
Ray.Compiler compiles Ray.Di bindings into PHP code, providing a performance boost that makes Dependency Injection couldn't be any faster.
Script Injector
ScriptInjector
has the same interface as Ray.Di Injector; whereas Ray.Di Injector resolves dependencies based on memory bindings, ScriptInjector executes pre-compiled PHP code and is faster.
Ray.Di injector
$injector = new Injector(new CarModule); // Ray.Di injector
Ray.Compiler injector
$injector = new ScriptInjector($tmpDir, fn => new CarModule);
Precompile
You will want to compile all dependencies into code before deploying the production. The DiCompiler
will compile all bindings into PHP code.
$compiler = new DiCompiler(new CarModule, $tmpDir); $compiler->compile();
Object graph visualization
Object graph can be visualized with dumpGraph()
.
Graph HTML files will be output at graph
folder under $tmpDir
.
$compiler = new DiCompiler(new Module, $tmpDir); $compiler->compile(); $compiler->dumpGraph();
open tmp/graph/Ray_Compiler_FakeCarInterface-.html
CompileInjector
The CompileInjector
gives you the best performance in both development (x2) and production (x10) by switching two injector.
Get the injector by specifying the binding and cache, depending on the execution context of the application.
$injector = new CompileInjector($tmpDir, $injectorContext);
$injectorContext
example:
The __invoke()
method prepares the modules needed in that context.
The getCache()
method specifies the cache of the injector itself.
Install DiCompileModule
in the context for production. The injector is more optimized and dependency errors are reported at compile-time instead of run-time.