bauhaus / service-resolver
PSR-11 的另一个实现
v0.2.0
2022-02-21 07:39 UTC
Requires
- php: ^8.1
- psr/container: ^2.0.2
Requires (Dev)
- phpunit/phpunit: ^9.5
README
警告! 此包不会关心
v0.*
的向后兼容性。
服务定位器
另一个遵循 PSR-11 容器接口 的服务解析器(也称为服务容器)实现。
安装
$ composer require bauhaus/service-resolver
使用它
<?php use Bauhaus\ServiceResolverSettings; $psrContainer = ServiceResolverSettings::new() ->withDefintionFiles( 'path/file-1.php', 'path/file-2.php', ) ->withServices([ 'service-id-1' => fn () => YourService(), // lazy loaded 'service-id-2' => new YourService(), ]) ->withDiscoverableNamespaces( 'App\\Namespace1', 'App\\Namespace2', ) ->build(); $psrContainer->has($serviceId); $psrContainer->get($serviceId);