Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
/ dice-wrapper Public archive

PSR-11 compliant for Level-2/Dice dependency injection container.

License

Notifications You must be signed in to change notification settings

pattisahusiwa/dice-wrapper

Repository files navigation

This repository is deprecated. Please use pattisahusiwa/dicontainer

Dice wrapper - PHP Dependency Injection Container

License Latest Stable Version Latest Unstable Version

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.

Installation

Use composer to install the package.

composer require pattisahusiwa/dice-wrapper

Usage

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');
}

Limitations

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)
    {
    }
}

Contributing

All form of contributions are welcome. You can report issues, fork the repo and submit pull request.

License

See the LICENSE file.