nalgoo/return-type-container

PSR-11 Container which gets entries based on return values of its public methods

1.0.0 2019-04-09 12:33 UTC

This package is auto-updated.

Last update: 2024-05-09 23:59:23 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);