2017 © Pedro Peláez
 

library root-container

This package contains a PHP DI container detector and aggregator. The idea is to have potentially one DI container per composer package and to aggregate all those containers into a 'root' container.

image

mouf/root-container

This package contains a PHP DI container detector and aggregator. The idea is to have potentially one DI container per composer package and to aggregate all those containers into a 'root' container.

  • Monday, February 9, 2015
  • by mouf
  • Repository
  • 16 Watchers
  • 1 Stars
  • 302 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

About RootContainer

RootContainer is a facade for a composite container that aggregates all DI containers detected in the application., (*1)

The big picture

The ultimate goal is to allow the application developer to easily create a "root container", that can automatically detect and add containers contained in other packages into a global composite container that can be used by the application., (*2)

Compared to the classical way of thinking about a web application, this is a paradigm shift., (*3)

In a "classical" application, packages added to the application may add new instances to the main and only DI container. This is what SF2 bundles, ZF2 modules or Mouf2 packages are doing., (*4)

Using this approach, each package provides its own DI container that contains instances. DI containers are added to a global container that is queried., (*5)

About this package

Detection of other containers is done using the Container-Installer component., (*6)

This package is using detected packages and aggregate those into a unique composite container. This container is exposed as a facade., (*7)

So basically, using RootContainer, you can access ANY instance of ANY container of your application using:, (*8)

$instance = RootContainer::get("instance_name");

In the background, RootContainer will load the containers.php file generated by Container-Installer and instanciate all the containers of the application., (*9)

A word of caution

Having an easy to use facade for containers does not allow you to use it all over the place :) Otherwise, you would be using the RootContainer as a service locator, which is considered by most people to be a bad practice (tip: the author of RootContainer thinks it is a bad practice too)., (*10)

So in a perfect world, the RootContainer should be used once or twice in your application, maybe by the MVC framework you are using, to fetch the controller, and that's it., (*11)

That being said, it's always useful to be able to access an instance quickly for testing purposes., (*12)

The Versions

09/02 2015

2.0.x-dev

2.0.9999999.9999999-dev http://mouf-php.com/packages/mouf/root-container

This package contains a PHP DI container detector and aggregator. The idea is to have potentially one DI container per composer package and to aggregate all those containers into a 'root' container.

  Sources   Download

The Requires

 

di containerinterop

16/01 2015

1.0.x-dev

1.0.9999999.9999999-dev http://mouf-php.com/packages/mouf/root-container

This package contains a PHP DI container detector and aggregator. The idea is to have potentially one DI container per composer package and to aggregate all those containers into a 'root' container.

  Sources   Download

The Requires

 

di containerinterop