streamcommon / factory-container-interop
默认带有PSR-11容器的工厂
此软件包的官方仓库似乎已不存在,因此该软件包已被冻结。
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
此软件包为PSR-11标准提供默认的FactoryInterface。
分支
安装
控制台运行
composer require streamcommon/factory-container-interop
或者添加到你的composer.json
"require": { "streamcommon/factory-container-interop": "*" }
示例
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); } }