File tree Expand file tree Collapse file tree 1 file changed +40
-2
lines changed Expand file tree Collapse file tree 1 file changed +40
-2
lines changed Original file line number Diff line number Diff line change 1- # null-container
2- Null (always empty) PSR-11 container implementation
1+ # NullContainer
2+
3+ ` NullContainer ` is a [ PSR-11] ( https://www.php-fig.org/psr/psr-11/ ) container implementation that is always empty.
4+
5+ This is useful when you want to provide an optional ` ContainerInterface ` dependency,
6+ but don't want to deal with nullable values.
7+
8+ ## Features
9+
10+ - PSR-11
11+ - PHP 7.0+
12+ - PHP 8.0
13+ - Semver
14+ - Tests
15+
16+ ## Example
17+
18+ ``` php
19+ use Psr\Container\ContainerInterface;
20+ use Technically\NullContainer\NullContainer;
21+
22+ final class MyServiceContainer implements ContainerInterface
23+ {
24+ private ContainerInterface $parent;
25+
26+ /**
27+ * @param ContainerInterface|null $parent
28+ */
29+ public function __construct(ContainerInterface $parent = null)
30+ {
31+ $this->parent = $parent ?? new NullContainer();
32+ }
33+
34+ // ... your code, where you don't need to deal with $parent set to `null`.
35+ }
36+ ```
37+
38+ ## Credits
39+
40+ - Implemented by [ Ivan Voskoboinyk] ( https://github.com/e1himself )
You can’t perform that action at this time.
0 commit comments