library ldc-zf1-di-leaguecontainer
Basic controller dependency injection in ZF1 with League\Container
adamlundrigan/ldc-zf1-di-leaguecontainer
Basic controller dependency injection in ZF1 with League\Container
- Thursday, July 2, 2015
- by adamlundrigan
- Repository
- 1 Watchers
- 2 Stars
- 16 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 1 Open issues
- 3 Versions
- 0 % Grown
LdcZf1DiLeagueContainer
, (*1)
What?
It's a simple glue layer which injects services registered in a League\Container into a ZF1 controller., (*2)
Heavily based on @weierophinney's now-many-moons-ago blog post "A Simple Resource Injector for ZF Action Controllers"., (*3)
How?
-
Install the Composer package:, (*4)
composer require adamlundrigan/ldc-zf1-di-league-container:1.*@stable
-
Register the helper in your ZF1 application bootstrap:, (*5)
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()
);
}
-
In each controller, define a list of dependencies to inject:, (*6)
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., (*7)
-
Profit! The injector will create a public property on the controller instance for each named service., (*8)
dev-master
9999999-dev
Basic controller dependency injection in ZF1 with League\Container
Sources
Download
BSD-3-Clause
The Requires
The Development Requires
1.1.0
1.1.0.0
Basic controller dependency injection in ZF1 with League\Container
Sources
Download
BSD-3-Clause
The Requires
The Development Requires
1.0.0
1.0.0.0
Basic controller dependency injection in ZF1 with League\Container
Sources
Download
BSD-3-Clause
The Requires
The Development Requires