 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Henrik Bjørnskov's Blog: Stampie an in depth look
by Chris Cornutt December 15, 2011 @ 12:48:25
Henrik Bjørnskov has posted a bit of an in-depth look at Stampie, an abstraction library for sending emails from PHP applications via various service providers (like SendGrid and Mailchimp).
So what is Stampie. Stampie is a API wrapper for the most common email sending services. It provides a standard PHP Api to send emails. But mostly it is a project to test TDD and experiment with a couple of different things. Stampie is developed with Dependency Injection and therefore there is a lot of objects. At the start it can be quite cumbersome, but will make a lot of sense if you start to develop and add additional provider.
He includes a bit of sample code showing the sending of a message via the SendGrid API backend. Extending the system is simpler thanks to DI and the customizable MailerInterface object type. There's also an AdapterInterface object that can be used to redefine the HTTP connection interface the tool uses. He also points to the HBStampieBundle bundle for the Symfony2 framework that can make dropping it into your current SF2 application simpler.
voice your opinion now!
stampie email send tutorial dependencyinjection tool
Devshed: Building a PHP ORM Deploying a Blog
by Chris Cornutt December 09, 2011 @ 11:13:18
DevShed concludes their three-part series about building an ORM in PHP with this latest article. It introduces the idea of dependency injection into the mix, showing how it can be used in the relationships between entities.
if you've already read the two installments that precede this one, it's probable that you're familiar with the inner workings of this sample ORM. In those chapters I implemented the ORM's data access and mapping layers, along with a simple domain model. To be frank, the development of this last tier is entirely optional; however, it's useful for demonstrating the ORM's actual functionality in the deployment of a blog program, which naturally will handle some "typical" domain objects, namely blog entries, comments and authors.
They share the code for creating proxy objects and, using a "poor man's dependency injection container" made from a factory method, interfaces and service classes to handle the results.
voice your opinion now!
orm dependencyinjection container deploy blog service interface
DevArticles.com: Singletons in PHP
by Chris Cornutt December 06, 2011 @ 10:17:33
On DevArticles.com today there's a new tutorial posted talking about one of the more popular design patterns, the Singleton, and how it can be implemented in PHP.
Though in the past they enjoyed both popularity and a certain amount of prestige, without a doubt Singletons have progressively become one of the most evil and despicable villains in object-oriented design. Singletons earned their bad reputation for a reason: bringing them to life requires the programmer to deal at least with a static method. This is simply an elegant masquerade for creating a global access point (which in most cases is mutable as well) throughout an entire application. And we all know that global, mutable access is unquestionably a bad thing that must be avoided at all costs.
In this first part (of two) of the series they introduce the Singleton pattern and show how, via an example of using a database adapter interface to work with a MySQL database, in a tightly coupled example.
In the second part of the series, they'll show how to break these apart using dependency injection.
voice your opinion now!
singleton designpattern dependencyinjection di mysql database adapter interface
Chris Hartjes' Blog: Scope Is Not a Mouthwash
by Chris Cornutt November 28, 2011 @ 09:50:03
Chris Hartjes has a reminder posted to his blog today in the form of this recent post that "scope is not a mouthwash" - personal experience from his recent development where he forgot about something as simple as scoping (and it caused him all sorts of headaches).
For [a chapter in my book on dependency injection] I am using Pimple, an incredibly small but effective dependency injection container. Easy to use, simple and effective documentation, just what I was looking for. I also noticed that Pimple supported the use of closures (or anonymous functions) as a way of storing a dependency. Then things got stupid.
He shares a bit of code showing how he added it to his bootstrap but was given a "cannot find class" error when he tried to use the tool. He walks through the steps he followed to track down the problem - looking closer at Pimple, investigating closures and, the ultimate problem, namespace scoping. He was missing a "" to start his namespace and closures work slightly differently:
So why does it behave differently inside closures? I am not 100% sure, but if I had to make an educated guess I would say that when trying to resolve namespaces inside a closure, the interpretor doesn't assume that it is already inside the global namespace, that it is in a namespace of it's own.
voice your opinion now!
namespace scoping pimple dependencyinjection
Padraic Brady's Blog: Zend Framework 2.0 Dependency Injection (Part 2)
by Chris Cornutt October 13, 2011 @ 09:14:09
Padraic Brady is back today with the second part of his "Dependency Injection in Zend Framework 2.0" series. In this second post he talks about what dependency injection containers are (and aren't) and how they could lead to bad practices if they're considered as service locators.
For Part 2, we're going to dig more into what a DIC is and isn't. I've already noted one very simple DIC called Pimple which will continue as one of my reference points since it best illustrates just how simple a DIC can be. In Part 3, we'll (finally) turn our attention to some actual source code. Baby steps. Parts 1 and 2 should get you thinking so that ZF 2.0′s DIC is a lot easier to understand and critique. We don't want anyone panicking just by throwing them into the deep end.
He talks more about the Pimple DIC tool and how, despite it's similarity to a set of Factory pattern calls, it's slightly different - think of it as "a container of executable Factories". He introduces the concept of a Service Locator, an object that can find and load other objects in an intelligent way. He notes that the most ideal DIC is an "external agent" that defines the object relationships outside of the application.
He points out a feature of ZF2 that allows for injection of the DIC into a controller, allowing it to look up the resources it needs. This of course, has issues - three that he mentions specifically:
- Firstly, this isn't Dependency Injection.
- Secondly, it creates objects which are useless without the specific DIC interface it depends on.
- Thirdly, DICs are really bad Service Locators.
voice your opinion now!
zendframework dependencyinjection dic pimple servicelocators
Wojciech Sznapka's Blog: Fully isolated tests in Symfony2
by Chris Cornutt June 15, 2011 @ 11:18:49
Wojciech Sznapka has a new post to his blog today looking at his creation of fully isolated tests as a part of a Symfony2 application. He talks about two issues he recently solved with testing services in this popular framework.
The most important thing you should provide with your re-usable bundles is unit tests set. Lately I solved two major cases which Symfony2 hasn't got out of the box: testing services, defined in Dependency Injection Container and running model tests with fixtures in fully isolated environment.
He includes code snippets for both solutions - a BaseTestClass for working with dependency injection testing and a ModelTestCase class that, in the setUp(), loads in the required fixtures so the test can be completely isolated.
voice your opinion now!
symfony2 isolated unittest dependencyinjection fixtures doctrine2
|
Community Events
Don't see your event here? Let us know!
|