PHP code example of b2pweb / bdf-instantiator
1. Go to this page and download the library: Download b2pweb/bdf-instantiator 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/ */
b2pweb / bdf-instantiator example snippets
use Bdf\Instantiator\Instantiator;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
/** @var ContainerInterface $container */
$container->add(Logger::class, LoggerInterface::class);
$instantiator = new Instantiator($container);
$instantiator->make(LoggerInterface::class);
use Bdf\Instantiator\Instantiator;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
class Foo
{
public $logger;
/**
* Foo constructor.
*
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
}
/** @var ContainerInterface $container */
$container->add(Logger::class, LoggerInterface::class);
$instantiator = new Instantiator($container);
$foo = $instantiator->make(Foo::class);
var_dump($foo->logger); // Logger