nalgoo / return-type-container
PSR-11 容器,根据其公共方法的返回值获取条目
1.0.0
2019-04-09 12:33 UTC
Requires
- psr/container: ^1.0
This package is auto-updated.
Last update: 2024-09-10 00:46:19 UTC
README
composer require nalgoo/return-type-container
用法
在你的服务类中使用 use ReturnTypeContainerTrait
或扩展 ReturnTypeContainer
示例
class ServiceContainer
{
use ReturnTypeContainerTrait;
public function getDatabaseConnection(): Connection
{
$connection = new Connection();
...
return $connection;
}
public function getLogger(): LoggerInterface
{
static $logger;
return $logger ?: $logger = new Logger();
}
// this ReturnType won't be accessible by `get` method
private function getDependency(): Dependency
{
return new Dependency();
}
}
ContainerChain
辅助类,用于能够链式使用多个 PSR-11 容器。
示例
$containerChain = new ContainerChain(
new FirstToSearchContainer(),
new SecondToSearchContainer()
);
$app = new App($containerChain);