Skip to content

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

License

Notifications You must be signed in to change notification settings

nalgoo/return-type-container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Install

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);

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages