News Feed
Sections




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

Gonzalo Ayuso:
Auto injecting dependencies in PHP objects
March 05, 2014 @ 09:19:38

In his latest post Gonzalo Ayuso shows how you can automatically inject dependencies into your PHP objects with the help of Pimple, a simple dependency injection container.

I must admit I don't really know what's the correct title for this post. Finally I use "Auto injecting dependencies in PHP objects". I know it isn't very descriptive. Let me explain it a little bit. This time I want to automate the Hollywood Principle ("Don't call us, we'll call you"). [...] We need to use Reflection to create our instance and to call our action. Sometimes I need to work with custom frameworks and legacy PHP applications. I've done it in a couple of projects, but now I want to create a library to automate this operation.

He includes a simple example of a "Controller" class that is injected with a "Request" via constructor injection. He refactors this to create the dependency injection container with a "Builder" class) and shows how to fetch the instance of the "Bar" class from it. It's this Builder class he shares on GitHub.

0 comments voice your opinion now!
dependency injection container pimple builder class tutorial

Link: http://gonzalo123.com/2014/03/03/auto-injecting-dependencies-in-php-objects/

blog comments powered by Disqus

Similar Posts

RubySource.com: Confessions of a Converted PHP Developer: Animal Abuse

Lineke Kerckhoffs-Willems' Blog: ProTalk - Audio/Video Tutorials for PHP Developers

David Makin: Creating a simple REST application with Silex

SitePoint PHP Blog: Cursors in MySQL Stored Procedures

Dave Dash's Blog: Saving a file to a database using symfony and doctrine


Community Events





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


bugfix opinion language interview tips list library introduction api install community package podcast voicesoftheelephpant deployment laravel series release symfony framework

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