nouvu/container

v2.1.2 2022-02-23 08:40 UTC

This package is auto-updated.

Last update: 2024-10-23 14:18:57 UTC


README

Latest Unstable Version License

Composer

composer require nouvu/container:^2.1.2

Examples

use Nouvu\Container\Container;
use Psr\Container\ContainerInterface;
 
require 'vendor/autoload.php';

class TestClass
{
    private int $int = 1;
    
    public function add(): void
    {
        $this -> int++;
    }
    
    public function get(): int
    {
        return $this -> int;
    }
}

//---------------------------------------

$container = new Container;

$container -> set( \Test :: class, function ( ContainerInterface $Container ): TestClass
{
    return new TestClass;
} );

//---------------------------------------

$test = $container -> get( \Test :: class ); // TestClass

$test -> add();

echo $test -> get(); // 2

$container -> reset( \Test :: class ); // reset class

$test = $container -> get( \Test :: class ); // new TestClass

echo $test -> get(); // 1