News Feed
Sections




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

MaltBlue.com:
Easy Setter Injection in Zend Framework 2
January 30, 2014 @ 11:54:40

Matthew Setter has a new post today looking at setter injection of dependencies in a Zend Framework v2 based application. He shows how to do it via ServiceManager-aware interfaces.

For configuring objects, reused throughout the application, I've found it to be nothing short of amazing. With next to no code, one Module configuration setting, along with the magic of OOP, classes are suitably initialized throughout the application, without any hands-on configuration on my part. Whilst Zend Framework 2 is great without this. When you start using setter injection, it becomes so much more. In today's post, I'll take you through an example which uses setter injection to ensure that the AuthService, or authenticated user object is always available to a class and any of its descendants.

He walks you through a basic implementation, showing the creation of the "AuthAwareInterface" interface class and an implementation of it, the "CacheableTable". In the "CacheableTable" there's a setter and getter for the currently authenticated user. Using these he's able to configure the ServiceManager to get the AuthService instance from the service locator and inject it into the class. He also includes a word of warning to be careful with the injection you do use, pointing out that it can lead to difficult to track bugs and issues down the line.

0 comments voice your opinion now!
zendframework2 setter injection servicemanager servicelocator tutorial

Link: http://www.maltblue.com/zend-framework/easy-setter-injection-in-zend-framework-2

blog comments powered by Disqus

Similar Posts

NETTUTS.com: How To Build a Widget to Display your Buzzing

Bill's IIS Blog: PHP on IIS7 w/FastCGI

DevShed: Managing Secure Protocol in Apache-Based Websites using PHP

PHPMaster.com: The Liskov Substitution Principle

Zend Developer Zone: Zend_Tool and ZF 1.8


Community Events





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


experience unittest introduction community threedevsandamaybe podcast symfony2 framework opinion refactor testing language laravel interview developer series list release code install

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