News Feed
Sections




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

Wojciech Sznapka's Blog:
Loosening dependencies with closures in PHP
September 27, 2011 @ 08:22:46

Wojciech Sznapka has a new tutorial posted to his blog today looking at removing some of the issues surrounding dependencies in PHP applications with the help of closures.

Today I ran into a little issue: how to pass generic logger object to method? I wanted to get some verbose output from method, which I call from Command, but onc time it should log with Symfony2 OutputInterface and other time it should use monolog logger. Of course I can make some wrapper class for both of them, but it would be kind of an overkill. The Closure from PHP 5.3 came with solution.

His alternative creates a closure for his Symfony2 application that defines the logger handling in an abstract way and injects that object into his job queue manager for handling. This way the manager doesn't have to worry about handing the mailing itself, it's just deferred to the mailing object. You can find out more about this technique, dependency injection, here.

0 comments voice your opinion now!
symfony2 dependency injection object email tutorial


blog comments powered by Disqus

Similar Posts

SaniSoft Blog: Lambda functions and Closures in PHP 5.3c

Zend Developer Zone: Tutorial : Using Zend Framework Without PDO

PHPBuilder.com: The ABC's of PHP Part 5 - Strings & Text

JellyandCustard.com: Using DirectoryIterator to List Files in PHP

PHPBuilder.com: My Automated PHP Scripts for Creating FTP Connections to a Remote Server


Community Events





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


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

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