chubbyphp / chubbyphp-laminas-config-factory
1.3.0
2023-11-27 20:46 UTC
Requires
- php: ^8.1
- psr/container: ^2.0.2
Requires (Dev)
- chubbyphp/chubbyphp-dev-helper: dev-master
- chubbyphp/chubbyphp-mock: ^1.7.0
- infection/infection: ^0.27.8
- php-coveralls/php-coveralls: ^2.7.0
- phpstan/extension-installer: ^1.3.1
- phpstan/phpstan: ^1.10.45
- phpunit/phpunit: ^10.4.2
README
描述
这是一个用于 laminas/laminas-servicemanager 及任何其他能够处理其配置的依赖注入容器(如 chubbyphp/chubbyphp-container 通过 chubbyphp/chubbyphp-laminas-config 以及许多其他容器(Aura.Di, Pimple, Auryn, Symfony, PHP-DI))的抽象服务工厂。
这个抽象服务工厂的原型是由 @DASPRiD 在 dasprid/container-interop-doctrine 中提出的,后来转交给 roave/psr-container-doctrine。
对概念的微小调整以及将其作为所有服务工厂的基础的可能性使我决定将其作为一个独立的仓库发布。
要求
- php: ^8.1
- psr/container: ^2.0.2
安装
通过 Composer 安装 chubbyphp/chubbyphp-laminas-config-factory。
composer require chubbyphp/chubbyphp-laminas-config-factory "^1.3"
使用方法
<?php declare(strict_types=1); namespace MyProject\Factory; use Chubbyphp\Laminas\Config\Factory\AbstractFactory; use MyProject\Service\ServiceA; use MyProject\Service\ServiceB; use MyProject\Service\ServiceC; use Psr\Container\ContainerInterface; final class ServiceAFactory extends AbstractFactory { public function __invoke(ContainerInterface $container): ServiceA { return new ServiceA( $this->resolveConfig($container->get('config')['serviceA'] ?? []), $this->resolveDependency($container, ServiceB::class, ServiceBFactory::class), $this->resolveDependency($container, ServiceC::class, ServiceCFactory::class) ); } } /** @var ContainerInterface $container */ $container = ...; // without name $serviceA = (new ServiceAFactory())($container); // with name $serviceA = [ServiceAFactory::class, 'default']($container);
版权
2024 Dominik Zogg