ray / compiler
Ray.Di 的依赖注入编译器
1.10.5
2024-05-10 11:55 UTC
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.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-09-10 12:41:50 UTC
README
依赖注入编译器
Ray.Compiler 将 Ray.Di 绑定编译成 PHP 代码,提供性能提升,使依赖注入的速度更快。
脚本注入器
ScriptInjector
与 Ray.Di 注入器具有相同的接口;而 Ray.Di 注入器基于内存绑定解析依赖,ScriptInjector 执行预编译的 PHP 代码,速度更快。
Ray.Di 注入器
$injector = new Injector(new CarModule); // Ray.Di injector
Ray.Compiler 注入器
$injector = new ScriptInjector($tmpDir, fn => new CarModule);
预编译
在部署生产环境之前,您需要将所有依赖编译成代码。 DiCompiler
将所有绑定编译成 PHP 代码。
$compiler = new DiCompiler(new CarModule, $tmpDir); $compiler->compile();
对象图可视化
对象图可以使用 dumpGraph()
进行可视化。HTML 图表文件将输出在 $tmpDir
下的 graph
文件夹中。
$compiler = new DiCompiler(new Module, $tmpDir); $compiler->compile(); $compiler->dumpGraph();
open tmp/graph/Ray_Compiler_FakeCarInterface-.html
CompileInjector
CompileInjector
通过切换两个注入器,在开发和生产环境中提供最佳性能(开发中提升2倍,生产中提升10倍)。
根据应用程序的执行上下文,通过指定绑定和缓存来获取注入器。
$injector = new CompileInjector($tmpDir, $injectorContext);
$injectorContext
示例
在 __invoke()
方法中准备该上下文所需的模块。 getCache()
方法指定注入器自身的缓存。
在生产环境中安装 DiCompileModule
。注入器更加优化,依赖错误在编译时而不是运行时报告。