Download the PHP package league/di without Composer

On this page you can find all versions of the php package league/di. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package di

League\Di

Build Status Dependencies Status Coverage Status Total Downloads Latest Stable Version

DEPRECATED: Use 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

Via Composer

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

Usage

Get a Container Object

include 'vendor/autoload.php';

$container = new League\Di\Container;

Bind a concrete class to an interface

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

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

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

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

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

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

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

There are two ways to create a child container.

$child = $continer->createChild();

// OR

$child = new Container($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

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of di with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package league/di contains the following files

Loading the files please wait ....