nouvu / container
Container php8
v2.1.2
2022-02-23 08:40 UTC
Requires
- php: ^8.0
- psr/container: ^1.1|^2
README
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