kerasai / container-aware
此包的最新版本(0.0.1)没有可用的许可证信息。
工具将容器注入到服务中。
0.0.1
2020-04-20 22:38 UTC
Requires
Requires (Dev)
- consolidation/robo: ~1
- drupal/coder: ^8.3
- kerasai/robo-phpcs: ^0.0.4
This package is auto-updated.
Last update: 2024-09-21 21:32:04 UTC
README
此包为使代码“容器感知”添加了实用工具。
用法
构建服务容器并自动将容器注入到所有容器感知服务中
<?php use Kerasai\ContainerAware\ContainerAwareCompilerPass; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; $containerBuilder = new ContainerBuilder(); $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__)); $loader->load('services.yml'); $containerBuilder->addCompilerPass(new ContainerAwareCompilerPass()); $containerBuilder->compile();
在你的服务中实现 \Symfony\Component\DependencyInjection\ContainerAwareInterface
接口。同时使用 \Symfony\Component\DependencyInjection\ContainerAwareTrait
以便轻松实现该接口。