Polymorphic IoC Container for PHP

v0.1 2017-08-17 21:43 UTC

This package is auto-updated.

Last update: 2023-09-11 12:16:11 UTC


Codeship Status for stephanecoinon/ioc-container

Versatile IoC container package that wraps around the container of the framework it's pulled in.

When this package is pulled in a framework (ie Laravel, Symfony...), it automatically detects it and wraps around the native IoC container of the framework.

When used in a vanilla PHP context, this package uses the PHP League container.

This is useful when developping an agnostic package that needs an IoC container but also ships with service providers for popular frameworks. It gives you a common IoC container API that leverages the framework native IoC container without your package ever pulling the framework itself.

Frameworks currently supported are:


  • PHP 7


composer require stephanecoinon/ioc-container



use StephaneCoinon\Container\Container;

require 'vendor/autoload.php';

// Boot the container
// You should add this line in your bootstrap or application service provider

// Store a key/value into the container
Container::add('foo', 'bar');

// Resolve a key out of the container
$bar = Container::get('foo');

// Check whether a key is stored in the container
if (Container::has('foo')) {
    echo 'Foo is in the container';

// Container instantiates a new instance if the key is an existing class that's
// not in the container yet
$object = Container::get('\My\Super\DuperClass');

// Get the native container instance
$nativeContainer = Container::getInstance();


This package is open-sourced software licensed under the MIT license.