PHPackages                             league/di - 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. league/di

Abandoned → [orno/di](/?search=orno%2Fdi)Library[Framework](/categories/framework)

league/di
=========

Fast Dependency Injection Container for PHP 5.3+

1.2.0(12y ago)603.6k6[2 issues](https://github.com/thephpleague/di/issues)[3 PRs](https://github.com/thephpleague/di/pulls)2MITPHPPHP &gt;=5.3.0

Since Jul 25Pushed 4y ago6 watchersCompare

[ Source](https://github.com/thephpleague/di)[ Packagist](https://packagist.org/packages/league/di)[ Docs](https://github.com/php-loep/di)[ RSS](/packages/league-di/feed)WikiDiscussions develop Synced 4w ago

READMEChangelogDependencies (1)Versions (5)Used By (2)

League\\Di
==========

[](#leaguedi)

[![Build Status](https://camo.githubusercontent.com/a42b4256dd005ade85d87e68094dd254ef66539209f5689042f2dd965bbc80a2/68747470733a2f2f7472617669732d63692e6f72672f7468657068706c65616775652f64692e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/thephpleague/di)[![Dependencies Status](https://camo.githubusercontent.com/dd693006e4b247534a80a759cbb9b584fb8b1b6950b2724f089a093fe9f1a2fd/68747470733a2f2f6432786973687470316f6a6c6b302e636c6f756466726f6e742e6e65742f642f3131363431343438)](http://depending.in/thephpleague/di)[![Coverage Status](https://camo.githubusercontent.com/d48fd8115e8393a2b341fd3a5baf8a208cacf6c70679c2c86e88745f77310fae/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7468657068706c65616775652f64692f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/thephpleague/di?branch=master)[![Total Downloads](https://camo.githubusercontent.com/234d186346b3c83af41be0ccd82af0115060bc951b49a72f206546500e97edd0/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f64692f646f776e6c6f6164732e706e67)](https://packagist.org/packages/league/di)[![Latest Stable Version](https://camo.githubusercontent.com/5fcb544e5f7f23105be9d7a73f58578776741b05b1702cc1b5e1c0556a830750/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f64692f762f737461626c652e706e67)](https://packagist.org/packages/league/di)

***DEPRECATED: Use [Orno\\Di](https://github.com/orno/di) instead as the two are incredibly similar, and theirs is more actively developed.***

The League\\Di library provides a fast and powerful Dependency Injection Container for your application.

Install
-------

[](#install)

Via Composer

```
{
    "require": {
        "league/di": ">=1.1"
    }
}

```

Usage
-----

[](#usage)

### Get a Container Object

[](#get-a-container-object)

```
include 'vendor/autoload.php';

$container = new League\Di\Container;

```

### Bind a concrete class to an interface

[](#bind-a-concrete-class-to-an-interface)

```
$container->bind('\Foo\Bar\BazInterface', '\Foo\Bar\Baz');

```

### Automatic Dependency Resolution

[](#automatic-dependency-resolution)

The Di Container is able to recursively resolve objects and their dependencies by inspecting the type hints on an object's constructor.

```
namespace Foo\Bar;

class Baz
{
  public function __construct(Qux $qux, Corge $corge)
  {
    $this->qux = $qux;
    $this->corge = $corge;
  }

  public function setQuux(Quux $quux)
  {
    $this->quux = $quux;
  }
}

$container->resolve('\Foo\Bar\Baz');

```

### Defining Arguments

[](#defining-arguments)

Alternatively, you can specify what to inject into the class upon instantiation.

#### Define Constructor Args

[](#define-constructor-args)

```
$container->bind('\Foo\Bar\Baz')->addArgs(array('\Foo\Bar\Quux', '\Foo\Bar\Corge'));

$container->resolve('\Foo\Bar\Baz');

```

#### Define Methods to Call with Args

[](#define-methods-to-call-with-args)

```
$container->bind('\Foo\Bar\Baz')->withMethod('setQuux', array('\Foo\Bar\Quux'));

$container->resolve('\Foo\Bar\Baz');

```

### Child Containers and Scope Resolution

[](#child-containers-and-scope-resolution)

A great feature of League\\Di is it's ability to provide child containers with a separate resolution scope to that of it's parent container. If you bind a concrete class to an interface within one container, you can re-bind it in the child container, without fear of overwriting the original binding in the parent container.

#### Creating a Child Container

[](#creating-a-child-container)

There are two ways to create a child container.

```
$child = $continer->createChild();

// OR

$child = new Container($container);

```

#### Using a Child Container

[](#using-a-child-container)

The primary benefit of using child containers is scope-specific resolution.

```
$container->bind('FooInterface', 'Foo');

// Assuming class Bar has a FooInterface dependency.
// This would use the Foo implementation.
$bar = $container->resolve('Bar');

// ...
$child = $container->createChild();
$child->bind('FooInterface', 'Baz');

// And this would use the Baz implementation.
$bar = $child->resolve('Bar');

```

TODO
----

[](#todo)

- Extensive Documentation

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/php-loep/di/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Don Gilbert](https://github.com/dongilbert)
- [All Contributors](https://github.com/php-loep/di/contributors)
- [Phil Bennett](https://twitter.com/philipobenito) / [Orno](http://getorno.com/)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/php-loep/di/blob/master/LICENSE) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 80.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

3

Last Release

4714d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/67381?v=4)[Phil Sturgeon](/maintainers/philsturgeon)[@philsturgeon](https://github.com/philsturgeon)

![](https://www.gravatar.com/avatar/3a5327d87a2a2d37a9412d5706442399763d86cb773f81adbe58c8d749393e2d?d=identicon)[alexbilbie](/maintainers/alexbilbie)

![](https://avatars.githubusercontent.com/u/718028?v=4)[Don Gilbert](/maintainers/dongilbert)[@dongilbert](https://github.com/dongilbert)

---

Top Contributors

[![dongilbert](https://avatars.githubusercontent.com/u/718028?v=4)](https://github.com/dongilbert "dongilbert (41 commits)")[![toopay](https://avatars.githubusercontent.com/u/534245?v=4)](https://github.com/toopay "toopay (6 commits)")[![ekho](https://avatars.githubusercontent.com/u/273418069?v=4)](https://github.com/ekho "ekho (3 commits)")[![marcqualie](https://avatars.githubusercontent.com/u/101022?v=4)](https://github.com/marcqualie "marcqualie (1 commits)")

---

Tags

dependency-injectioniocdic

### Embed Badge

![Health badge](/badges/league-di/health.svg)

```
[![Health](https://phpackages.com/badges/league-di/health.svg)](https://phpackages.com/packages/league-di)
```

###  Alternatives

[rdlowrey/auryn

Auryn is a dependency injector for bootstrapping object-oriented PHP applications.

7242.3M77](/packages/rdlowrey-auryn)[nette/di

💎 Nette Dependency Injection Container: Flexible, compiled and full-featured DIC with perfectly usable autowiring and support for all new PHP features.

93041.5M1.6k](/packages/nette-di)[mouf/mouf

The Mouf PHP framework: an open-source PHP framework providing an easy way to download, install, use and reuse components, with a graphical user interface.

55146.3k17](/packages/mouf-mouf)[joomla/di

Joomla DI Package

15433.2k12](/packages/joomla-di)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
