neighborhoods/dependency-injection-container-builder
Composer 安装命令:
composer require neighborhoods/dependency-injection-container-builder
包简介
A dependency injection container builder based on Symfony.
README 文档
README
Basic example of usage
$container = (new \Neighborhoods\DependencyInjectionContainerBuilderComponent\TinyContainerBuilder()) ->setContainerBuilder(new \Symfony\Component\DependencyInjection\ContainerBuilder()) ->setRootPath(dirname(__DIR__)) ->addSourcePath('src/ComponentName') ->addSourcePath('src/Prefab5') ->addSourcePath('fab/ComponentName') ->makePublic(SomeRepository::class) ->addCompilerPass(new \Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass()) ->addCompilerPass(new \Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass()) ->build();
setContainerBuilder: the setter takes instance of\Symfony\Component\DependencyInjection\ContainerBuilder. It's possible to supply non-empty container.setRootPath: takes the path to the project root (wheresrcandfabfolders are located)addSourcePath: takes the path to a folder containing definitions for Container BuildermakePublic: takes the service URI (usually class name) and makes it publicmakeAllPublic: makes all services publicaddCompilerPass: takes instance of\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterfaceand supplies it to theaddCompilerPassmethod of ContainerBuilder.build: creates and returns an instance of\Psr\Container\ContainerInterface
With Cache
If container needs to be cached, a \Neighborhoods\DependencyInjectionContainerBuilderComponent\CacheHandlerInterface
can be supplied through setCacheHandler.
$cacheHandler = (new \Neighborhoods\DependencyInjectionContainerBuilderComponent\SymfonyConfigCacheHandler\Builder()) ->setName('ContainerName') ->setCacheDirPath(dirname(__DIR__) . '/data/cache') ->setDebug(true) ->build(); $container = (new \Neighborhoods\DependencyInjectionContainerBuilderComponent\TinyContainerBuilder()) // ... ->setCacheHandler($cacheHandler) ->build();
setName: takes the name of the cached Container classsetCacheDirPath: takes the path to directory where container file is going to be stored (absolute)setDebug: takes a boolean flag whether "debug mode" should be on or off. When debug mode is on, cache is going to "listen" for the changes in source configuration files. If any change is introduced, cache would be considered invalid, and a new one will be generated and stored. It's advised to usetrueonly for development.
统计信息
- 总下载量: 10.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2021-01-11