streamcommon / factory-container-interop
Default factory with PSR-11 container
This package's canonical repository appears to be gone and the package has been frozen as a result.
1.0.3
2019-02-16 19:55 UTC
Requires
- php: ^7.2
- psr/container: ^1.0
Requires (Dev)
- malukenho/docheader: ^0.1.7
- php-coveralls/php-coveralls: ^2.1.0
- phpstan/phpstan: ^0.11.1
- phpunit/phpunit: ^8.0
- streamcommon/coding-standard: ^1.0.0
This package is auto-updated.
Last update: 2019-12-08 20:34:23 UTC
README
This package provide default FactoryInterface
for PSR-11 standard.
Branches
Installation
Console run:
composer require streamcommon/factory-container-interop
Or add into your composer.json
:
"require": { "streamcommon/factory-container-interop": "*" }
Example
use Psr\Container\ContainerInterface; use Streamcommon\Factory\Container\Interop\{FactoryInterface, CallableFactoryTrait}; use Streamcommon\Factory\Container\Interop\Exception\NotFoundException; class FooFactory implements FactoryInterface { // if you want used as static factory [FooFactory::class, 'name'] use CallableFactoryTrait; /** * Create an object * * @param ContainerInterface $container * @param string $requestedName * @param null|array $options * @return object * @throws NotFoundException A call to the get method with a non-existing object */ public function __invoke(ContainerInterface $container, string $requestedName, ?array $options = null): object { if (!class_exists($requestedName)) { throw new NotFoundException(); } return new $requestedName($options); } }