2017 © Pedro Peláez
 

library mnapoli-php-di

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

image

radutopala/mnapoli-php-di

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  • Wednesday, June 12, 2013
  • by radutopala
  • Repository
  • 1 Watchers
  • 0 Stars
  • 51 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 200 Forks
  • 0 Open issues
  • 19 Versions
  • 0 % Grown

The README.md

PHP-DI is a Container that makes Dependency Injection as practical as possible., (*1)

PHP-DI also tries to avoid falling into the trap of the "Service Locator" antipattern and help you do real dependency injection., (*2)

Features

  • Simple to start with
  • Supports different configuration alternatives to suit every taste:
    • Reflection: zero configuration, intelligent guessing
    • Annotations: modern, practical and simple
    • PHP code: if you like complete control and auto-completion
    • PHP array: allows you to store it in a configuration file
    • YAML: elegant and concise
    • XML (work in progress): more verbose, but more classic
  • Performances: supports a large number of Caches
  • Offers lazy injection: lazy-loading of dependencies (WIP)
  • Supports constructor injection, setter injection and property injection

Usage

Let's go to the Getting started guide!, (*3)

And there is a complete documentation waiting for you., (*4)

What is dependency injection, and why use PHP-DI

You can first read the introduction to dependency injection with an example., (*5)

Dependency injection and DI containers are separate notions, and one should use of a container only if it makes things more practical (which is not always the case depending on the container you use)., (*6)

PHP-DI is about this: make dependency injection more practical., (*7)

How classic PHP code works

Here is how a code not using DI will roughly work:, (*8)

  • Application needs Foo (e.g. a controller), so:
  • Application creates Foo
  • Application calls Foo
    • Foo needs Bar (e.g. a service), so:
    • Foo creates Bar
    • Foo calls Bar
      • Bar needs Bim (a service, a repository, …), so:
      • Bar creates Bim
      • Bar does something

How Dependency Injection works

Here is how a code using DI will roughly work:, (*9)

  • Application needs Foo, which needs Bar, which needs Bim, so:
  • Application creates Bim
  • Application creates Bar and gives it Bim
  • Application creates Foo and gives it Bar
  • Application calls Foo
    • Foo calls Bar
      • Bar does something

This is the pattern of Inversion of Control. The control of the dependencies is inversed from one being called to the one calling., (*10)

The main advantage: the one at the end of the caller chain is always you. So you can control every dependencies: you have a complete control on how your application works. You can replace a dependency by another (one you made for example)., (*11)

For example that wouldn't be so easy if Library X uses Logger Y and you have to change the code of Library X to make it use your logger Z., (*12)

How code using PHP-DI works

Now how does a code using PHP-DI works:, (*13)

  • Application needs Foo so:
  • Application gets Foo from the Container, so:
    • Container creates Bim
    • Container creates Bar and gives it Bim
    • Container creates Foo and gives it Bar
  • Application calls Foo
    • Foo calls Bar
      • Bar does something

In short, PHP-DI takes away all the work of creating and injecting dependencies., (*14)

The Versions

12/06 2013

dev-master

9999999-dev http://mnapoli.github.com/PHP-DI/

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  Sources   Download

MIT

The Requires

 

dependency injection container di

12/06 2013

3.1.x-dev

3.1.9999999.9999999-dev http://mnapoli.github.com/PHP-DI/

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  Sources   Download

MIT

The Requires

 

dependency injection container di

11/06 2013

3.0.5

3.0.5.0 http://mnapoli.github.com/PHP-DI/

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  Sources   Download

MIT

The Requires

 

dependency injection container di

10/06 2013

3.0.4

3.0.4.0 http://mnapoli.github.com/PHP-DI/

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  Sources   Download

MIT

The Requires

 

dependency injection container di

10/06 2013

3.0.3

3.0.3.0 http://mnapoli.github.com/PHP-DI/

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  Sources   Download

MIT

The Requires

 

dependency injection container di

22/05 2013

3.0.2

3.0.2.0 http://mnapoli.github.com/PHP-DI/

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  Sources   Download

MIT

The Requires

 

dependency injection container di

21/05 2013

dev-error-handling

dev-error-handling http://mnapoli.github.com/PHP-DI/

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  Sources   Download

MIT

The Requires

 

dependency injection container di

05/05 2013

3.0.1

3.0.1.0 http://mnapoli.github.com/PHP-DI/

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  Sources   Download

MIT

The Requires

 

dependency injection container di

23/04 2013

3.0.0

3.0.0.0 http://mnapoli.github.com/PHP-DI/

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

  Sources   Download

MIT

The Requires

 

dependency injection container di

29/01 2013

2.1.0

2.1.0.0 http://mnapoli.github.com/PHP-DI/

PHP dependency injection using annotations

  Sources   Download

MIT

The Requires

 

dependency injection container di

09/12 2012

2.0.1

2.0.1.0 http://mnapoli.github.com/PHP-DI/

PHP dependency injection using annotations

  Sources   Download

MIT

The Requires

 

dependency injection container di

05/12 2012

2.0.0

2.0.0.0 http://mnapoli.github.com/PHP-DI/

PHP dependency injection using annotations

  Sources   Download

MIT

The Requires

 

dependency injection container di

05/12 2012

dev-ContextualizedInjection

dev-ContextualizedInjection http://mnapoli.github.com/PHP-DI/

PHP dependency injection using annotations

  Sources   Download

MIT

The Requires

 

dependency injection container di

01/11 2012

1.1.0

1.1.0.0 http://mnapoli.github.com/PHP-DI/

PHP dependency injection using annotations

  Sources   Download

LGPL

The Requires

 

dependency injection container di

26/10 2012

1.0.3

1.0.3.0 http://mnapoli.github.com/PHP-DI/

PHP dependency injection using annotations

  Sources   Download

LGPL

The Requires

 

dependency injection container di

26/10 2012

1.0.2

1.0.2.0 http://mnapoli.github.com/PHP-DI/

PHP dependency injection using annotations

  Sources   Download

LGPL

The Requires

 

dependency injection container di

26/10 2012

1.0.1

1.0.1.0 http://mnapoli.github.com/PHP-DI/

PHP dependency injection using annotations

  Sources   Download

LGPL

The Requires

 

dependency injection container di

06/10 2012

1.0.0

1.0.0.0

  Sources   Download

The Requires

 

29/09 2012

0.9.0

0.9.0.0

  Sources   Download

The Requires