PHPackages                             luna-fw/container - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. luna-fw/container

ActiveLibrary[Framework](/categories/framework)

luna-fw/container
=================

1.0.0(7y ago)28[1 issues](https://github.com/luna-fw/djinn/issues)[1 PRs](https://github.com/luna-fw/djinn/pulls)MITPHPCI failing

Since Nov 10Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/luna-fw/djinn)[ Packagist](https://packagist.org/packages/luna-fw/container)[ RSS](/packages/luna-fw-container/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Djinn - DI Container
====================

[](#djinn---di-container)

[![Build Status](https://camo.githubusercontent.com/f0fa7df8fa163c75f7da7d32aa04c1f0f47a8db7181d3c4c20a7598aa653e104/68747470733a2f2f7472617669732d63692e6f72672f6c756e612d66772f636f6e7461696e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/luna-fw/container)[![Latest Stable Version](https://camo.githubusercontent.com/d48a83c29eaeeee7a533d2830487bb522c7426552d053020f6af0ee3a21d6464/68747470733a2f2f706f7365722e707567782e6f72672f6c756e612d66772f636f6e7461696e65722f762f737461626c65)](https://packagist.org/packages/luna-fw/container)[![Total Downloads](https://camo.githubusercontent.com/8389c975bb7ab100865aba4146671def00963339ec281ab8a4cd8071e3c5924d/68747470733a2f2f706f7365722e707567782e6f72672f6c756e612d66772f636f6e7461696e65722f646f776e6c6f616473)](https://packagist.org/packages/luna-fw/container)[![License](https://camo.githubusercontent.com/1fb3119df9c7770da20e8bbed18d23783b3851e5000bb2370d9928bc98702412/68747470733a2f2f706f7365722e707567782e6f72672f6c756e612d66772f636f6e7461696e65722f6c6963656e7365)](https://packagist.org/packages/luna-fw/container)

Djinn is a full featured DI container for PHP. We call it Djinn, because a DI container is pretty much as a Djinn: It grants wishes (dependencies) to his master (the caller).

Install
-------

[](#install)

The package must be installed using composer:

```
composer require luna-fw/djinn

```

Or include `luna-fw/djinn` on your `composer.json` dependencies.

Usage
-----

[](#usage)

This package implements the PSR-11 interfaces and Exceptions:

- `Psr\Container\ContainerInterface`
    - `has(key)` - Return an instance based on a string key
    - `get(key)` - Return true if there is an entry for the given instance
- `Psr\Container\ContainerExceptionInterface`
- `Psr\Container\NotFoundExceptionInterface`

For further details, please refer to:

We consider the PSR-11 specification too much simple, so we added some additional interfaces to the implementation (those extended implementations don't prevent someone to use the container as a PSR-11 compatible container).

Here are the extended interfaces:

- `ContainerConfigContract` - Holds the methods related with the container config.
    - `bind` - Configures the resolution of a given key
    - `singleton` - Configures the resolution of a given key, always returning and immutable instance (singleton).
    - `contextual` - Same as bind, but the resolution depends on "who" is asking for the instance.
    - `contextualSingleton` - Same as contextual, but always return an immutable instance (singleton).
- `ExtendedContainerContract` - Holds the methods related with the DI injection/resolution.
    - `getFor` - Returns an instance of the required class or interface, resolving all the dependencies, based on the defined configs. Allow contextual binding.
    - `run` - Executes a method, resolving all it's dependencies, based on the defined config.

To use it, you need to have the `vendor/autoload.php` file included. Then all you have to do is to instantiate the `Luna\Djinn` class and star using it.

```
