chubbyphp / chubbyphp-laminas-config-factory
Installs: 30 433
Dependents: 14
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
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
Description
An abstract service factory for the laminas/laminas-servicemanager and any other dependency injection container who's been able to handle it's config, like chubbyphp/chubbyphp-container via chubbyphp/chubbyphp-laminas-config and many (Aura.Di, Pimple, Auryn, Symfony, PHP-DI) more.
The original concept of this abstract service factory is by @DASPRiD used in dasprid/container-interop-doctrine which was handed over to roave/psr-container-doctrine.
Small adjustments and the possibility to use the concept as a basis for all service factories led me to make it available as an independent repository.
Requirements
- php: ^8.1
- psr/container: ^2.0.2
Installation
Through Composer as chubbyphp/chubbyphp-laminas-config-factory.
composer require chubbyphp/chubbyphp-laminas-config-factory "^1.3"
Usage
<?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);
Copyright
2024 Dominik Zogg