https://github.com/technically-php/null-container
🕳️ Always-empty PSR-11 container implementation. :elephant: PHP8-ready :fire:
https://github.com/technically-php/null-container
container null null-object php psr-11
Last synced: about 2 months ago
JSON representation
🕳️ Always-empty PSR-11 container implementation. :elephant: PHP8-ready :fire:
- Host: GitHub
- URL: https://github.com/technically-php/null-container
- Owner: technically-php
- License: mit
- Created: 2021-02-24T15:25:57.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-08-04T12:13:44.000Z (8 months ago)
- Last Synced: 2025-09-07T01:57:40.278Z (7 months ago)
- Topics: container, null, null-object, php, psr-11
- Language: PHP
- Homepage:
- Size: 23.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Technically Null Container
`Technically\NullContainer` is a [PSR-11][1] container implementation that is always empty.
This is a [NullObject][2] pattern implementation for PSR-11.
This is useful when you want to provide an optional `ContainerInterface` dependency,
but don't want to deal with nullable values.
![Tests Status][status-badge]
## Features
- PSR-11
- PHP 8.0+
- Semver
- Tests
- Changelog
## Installation
Use [Composer][3] package manager to add *NullContainer* to your project:
```
composer require technically/null-container
```
## Example
```php
use Psr\Container\ContainerInterface;
use Technically\NullContainer\NullContainer;
final class MyServiceContainer implements ContainerInterface
{
private ContainerInterface $parent;
/**
* @param ContainerInterface|null $parent
*/
public function __construct(ContainerInterface $parent = null)
{
$this->parent = $parent ?? new NullContainer();
}
// ... your code, where you don't need to deal with $parent set to `null`.
}
```
## Changelog
All notable changes to this project will be documented in the [CHANGELOG][changelog] file.
## Credits
- Implemented by [Ivan Voskoboinyk][4]
[1]: https://www.php-fig.org/psr/psr-11/
[2]: https://en.wikipedia.org/wiki/Null_object_pattern
[3]: https://getcomposer.org/
[4]: https://github.com/e1himself?utm_source=web&utm_medium=github&utm_campaign=technically/null-container
[status-badge]: https://github.com/technically-php/null-container/actions/workflows/test.yml/badge.svg
[changelog]: ./CHANGELOG.md