nalgoo / return-type-container
PSR-11 Container which gets entries based on return values of its public methods
Installs: 2 121
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- psr/container: ^1.0
This package is auto-updated.
Last update: 2025-04-10 02:03:00 UTC
README
composer require nalgoo/return-type-container
Usage
Either use ReturnTypeContainerTrait
in your service class or extend ReturnTypeContainer
Example:
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
Helper class to be able to chain multiple PSR-11 containers.
Example:
$containerChain = new ContainerChain(
new FirstToSearchContainer(),
new SecondToSearchContainer()
);
$app = new App($containerChain);