This repository is deprecated. Please use pattisahusiwa/dicontainer
PSR-11 compliant for Level-2/Dice dependency injection container.
Dice is a minimalist Dependency Injection Container for PHP with a focus on being lightweight and fast as well as requiring as little configuration as possible.
Use composer to install the package.
composer require pattisahusiwa/dice-wrapper
Please check Dice documentation for detail usage.
// Create new Dice instance
$dice = new Dice();
// You can also pass your dependencies configuration into Dice instance
$dice = $dice->addRules('rules.json');
// Pass dice instance to DiceWrapper
$diceWrapper = new DiceWrapper($dice);
// example usage
if ($diceWrapper->has('class_name')) {
$object = $diceWrapper->get('class_name');
}
You can't use DICE::SELF
in order to get DiceWrapper
instance. DICE::SELF
will return Dice
instance.
Current workaround is by adding Psr\Container\ContainerInterface
in your class constructor. The injector and the injected DiceWrapper
are the same object. However, you must carefully implement this into your projects as it can turn into a Service Locator.
<?php
use Psr\Container\ContainerInterface;
final class ExampleClass
{
public function __construct(ContainerInterface $dic)
{
}
}
All form of contributions are welcome. You can report issues, fork the repo and submit pull request.
See the LICENSE file.