Technically\NullContainer
is a PSR-11 container implementation that is always empty.
This is a NullObject 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.
- PSR-11
- PHP 8.0+
- Semver
- Tests
- Changelog
Use Composer package manager to add NullContainer to your project:
composer require technically/null-container
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`.
}
All notable changes to this project will be documented in the CHANGELOG file.
- Implemented by Ivan Voskoboinyk