News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Reese Wilson:
Using the ServiceManager as an Inversion of Control Container (Part 1)
October 01, 2012 @ 08:04:02

The this recent post to his blog Reese Wilson looks at using one of the modules of the Zend Framework v2, the ServiceManager, as an inversion of control container in your app.

In Zend Framework 1, it was difficult to follow best practices when it came to writing testable code. Sure, you could make testable models, but once you need those models in a controller, what do you do? Zend Framework 2 makes it much easier. In this post, I'll cover the basics of injecting a model into a controller. The main goal here is to be able to wire up and configure your application from the highest level possible. Constructor injection + inversion of control makes it easy to determine which classes are dependent on other classes.

He creates a "Building" module and a "BuildingController" inside of it. This controller takes in an instance of a "Building" model as a dependency. He also shows how to define this dependency in the "getControllerConfig" method of your module to make it work automatically. He makes the "Building" model itself with no dependencies and sets it up as an "invokable" in that same "getControllerConfig" method.

0 comments voice your opinion now!
servicemanager zendframework2 inversionofcontrol ioc designpattern


blog comments powered by Disqus

Similar Posts

PHPMaster.com: Manage Complexity with the Facade Pattern

Matthew Weier O'Phinney's Blog: Introducing the ZF2 Plugin Broker

Master Zend Framework: Create a Simple File Upload Form in Zend Framework 2

Matthew Weier O'Phinney's Blog: Getting started writing ZF2 modules

MaltBlue.com: Zend Framework 2 - Hydrators, Models and the TableGateway Pattern


Community Events





Don't see your event here?
Let us know!


series project wordpress developer bugfix community threedevsandamaybe language list laravel application framework release library configure introduction code interview podcast api

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework