PHP code example of nouvu / container
1. Go to this page and download the library: Download nouvu/container library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nouvu / container example snippets
use Nouvu\Container\Container;
use Psr\Container\ContainerInterface;
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