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

MaltBlue.com:
Zend Framework 2 Core Concepts - Dependency Injection
Dec 17, 2012 @ 16:09:53

In this new post Matthew Setter has posted about one of the core concepts behind the structure and use of Zend Framework 2, its use of dependency injection to handy object relationships and access (via Zend/Di).

As Zend Framework 2 is well and truly here, before some of us who are new to it dive right on in, whether you’re completely new or, like me, migrating from Zend Framework 1, it’s really important to ensure that we understand the core concepts on which it’s based. [...] In this, the first part in the series, I’m going to go through what dependency injection (DI) is. However, as there are a number of great posts already available on the topic by some very experienced developers, [...] I’m not going to rehash them.

Instead he extracts out useful tips from posts of a few other sources on ZF2 and dependency injection in general: Matthew Weier O'Phinny, the ZF2 manual, Martin Fowler on dependency injection, Wikipedia and more. He also includes lots of links to more great articles on the subject, both ZF2-specific and for DI iin general.

tagged: zendframework2 dependency injection zenddi component quotes

Link:

Evan Coury's Blog:
Sharing a database connection across modules in Zend Framework 2
Apr 27, 2012 @ 14:54:56

Evan Coury has a new post to his site about a handy method for sharing database connections across modules in a Zend Framework application.

With the new modular infrastructure in Zend Framework 2, one of the most common questions will indoubitably be how to share a database connection across modules. Here’s a quick explanation of how to share your database connection across multiple modules in a way that can even allow you to use a single connection between ZendDb, Doctrine2, and possibly even other database libraries / ORMs.

He includes the code in the post to configure this application-wide database resource, a "masterdb_pdo" that uses a MySQL backend. This configuration is used to set up the connection in a dependency injection container for later (globalish) use. He also mentions something similar about sharing Doctrine connections with the ZendDb components (using the same DI container approach).

tagged: share database connection module application zenddb zenddi doctrine2

Link:

Rob Allen's Blog:
An introduction to ZendDi
Feb 29, 2012 @ 15:16:20

Rob Allen, Zend Framework guru extraordinaire, has posted an introduction to the Dependency Injection container that's a part of Zend Framework 2 - ZendDi.

Zend Framework 2 provides its own dependency injection container, ZendDi which is a key underpinning of the entire framework and especially the MVC system. I have covered before, my thoughts on the reasons for using dependency injection, so this article looks at the fundamentals of using ZendDi.

He includes some sample code showing a current setup involving constructor injection and how it can be refactored to use the new DI container. With the new version, the resource is assigned to the container and that is referenced when a new object type needs to be created. He also briefly touches on setter injections, noting that he prefers them more for optional dependencies and shows how to enable their use in the container as well.

tagged: zendframework2 dependency injection zenddi container tutorial

Link:


Trending Topics: