Skip to content

Commit 0bdbc10

Browse files
authored
Update README.md
1 parent 940fd58 commit 0bdbc10

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,40 @@
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)

0 commit comments

Comments
 (0)