adamlundrigan/ldc-zf1-di-leaguecontainer

Basic controller dependency injection in ZF1 with League\Container

Maintainers

👁 adamlundrigan

Package info

github.com/adamlundrigan/ldc-zf1-di-leaguecontainer

pkg:composer/adamlundrigan/ldc-zf1-di-leaguecontainer

Statistics

Installs: 32

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 1

1.1.0 2015-07-02 16:57 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

BSD-3-Clause 3390478ec1cdd1bc8d3fc18977e1f413b98cc7a7

  • Adam Lundrigan <adam.woop@lundrigan.ca>

This package is not auto-updated.

Last update: 2026-06-21 03:13:05 UTC


README

👁 Latest Stable Version
👁 License
👁 Build Status
👁 Code Coverage
👁 Scrutinizer Code Quality

What?

It's a simple glue layer which injects services registered in a League\Container into a ZF1 controller.

Heavily based on @weierophinney's now-many-moons-ago blog post "A Simple Resource Injector for ZF Action Controllers".

How?

  1. Install the Composer package:

    composer require adamlundrigan/ldc-zf1-di-league-container:1.*@stable
    
  2. Register the helper in your ZF1 application bootstrap:

    protected function _initContainer()
    {
     $container = new League\Container\Container();
     // Fill your container 
     return $container;
    }
    
    protected function _initContainerResourceInjector()
    {
     $this->bootstrap('container');
     
     Zend_Controller_Action_HelperBroker::addHelper(
     new \LdcZf1DiLeagueContainer\DependencyInjector()
     );
    }
    
  3. In each controller, define a list of dependencies to inject:

    class FooController extends Zend_Controller_Action
    {
     public $dependencies = array(
     'db',
     'layout',
     'navigation',
     );
    }
    

    If you use a non-numeric key for any value of $dependencies the injector will use that as the controller property to inject into.

  4. Profit! The injector will create a public property on the controller instance for each named service.