# PSR-11 Container Interface

✨ Wraps nette/di container (opens new window) into PSR-11 (opens new window) implementation.

# Content

# Configuration

Register extension:

extensions:
	psr11: Contributte\Psr11\DI\Psr11ContainerExtension
1
2

# Usage

use Psr\Container\ContainerInterface;

class YourService
{

	/** @var ContainerInterface $container */
	private $container;

	public function __construct(ContainerInterface $container)
	{
		$this->container = $container;
	}

	private function workWithService(): void
	{
		if($this->container->has('serviceName')) {
			/** @var YourAnotherService $service */
			$service = $this->container->get('serviceName');
		}
	}

	private function workWithServiceOfType(): void
	{
		if($this->container->has(YourAnotherService::class)) {
			/** @var YourAnotherService $service */
			$service = $this->container->get(YourAnotherService::class);
		}
	}

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31