b2pweb / bdf-instantiator
Bdf Instantiator component
Installs: 6 769
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ~7.2 | ~8.0.0 | ~8.1.0 | ~8.2.0 | ~8.3.0
- psr/container: ~1.0|~2.0
- symfony/http-kernel: ~4.2|~5.0|~6.0|~7.0
Requires (Dev)
- league/container: ~3.0|~4.0
- phpunit/phpunit: ~7.0|~8.0
README
A basic object instantiator.
Install via composer
$ composer require b2pweb/bdf-instantiator
Usage Instruction
Basic usage when resolving from container definition.
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);
The instantiator resolve the dependencies of a method based on container definitions.
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
License
Distributed under the terms of the MIT license.