Skip to content

🕳️ Always-empty PSR-11 container implementation. 🐘 PHP8-ready 🔥

License

Notifications You must be signed in to change notification settings

technically-php/null-container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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