https://github.com/b2pweb/bdf-instantiator
https://github.com/b2pweb/bdf-instantiator
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/b2pweb/bdf-instantiator
- Owner: b2pweb
- License: mit
- Created: 2019-12-16T15:11:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-12-11T10:49:49.000Z (7 months ago)
- Last Synced: 2025-12-12T11:27:38.150Z (7 months ago)
- Language: PHP
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# B2PWeb Instantiator
A basic object instantiator.
[](https://github.com/b2pweb/bdf-instantiator/actions/workflows/php.yml)
[](https://app.codecov.io/github/b2pweb/bdf-instantiator)
[](https://packagist.org/packages/b2pweb/bdf-instantiator)
[](https://packagist.org/packages/b2pweb/bdf-instantiator)
## Install via composer
```bash
$ composer require b2pweb/bdf-instantiator
```
## Usage Instruction
Basic usage when resolving from container definition.
```PHP
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.
```PHP
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.