Skip to content

Latest commit

 

History

History
69 lines (44 loc) · 1.54 KB

README.md

File metadata and controls

69 lines (44 loc) · 1.54 KB

Technically Null Container

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.

Tests Status

Features

  • PSR-11
  • PHP 8.0+
  • Semver
  • Tests
  • Changelog

Installation

Use Composer package manager to add NullContainer to your project:

composer require technically/null-container

Example

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 file.

Credits