News Feed
Sections




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

Juan Treminio:
An introduction to Pimple and Service Containers
October 05, 2012 @ 11:18:02

Juan Treminio has a new post to his site introducing the ideas behind Pimple and service containers, two very similar approaches to dependency management in your applications.

Recently I've picked up the Silex framework for a project I'm building. It uses a service container for managing dependencies in your application [Pimple], which is great for defining (not instantiating) objects and their default behaviors in a single location, rather than sprinkled throughout your code in a multitude of places. [...] Using Pimple you can define several hundreds of objects, and then easily instantiate them using the container object.

He goes through some example code showing how to use Pimple to create and manage the dependencies by creating several instances of DateTime objects. He shows how this can then be "upgraded" to a service container by defining something like a PDO object (database connection) inside it. He also mentions some of the benefits that come with its use - easy resource swapping, simpler mocking for testing and allows the use of the Inversion of Control pattern.

0 comments voice your opinion now!
pimple service container resource dependency tutorial


blog comments powered by Disqus

Similar Posts

Robert Basic's Blog: Creating a chat bot with PHP and Dbus

Davey Shafik: Everything You Need to Know About OpCode Caches

DZone.com: Development Setup for Neo4j and PHP: Part 2

Geeks Not Nerds Blog: Rolling your own Blog Backend from Scratch Part 1

Chris Renner's Blog: Gerrymandered Code: Extending Zend_Registry to globalize session vars


Community Events

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


interview api community symfony introduction series list yii2 project composer framework example language testing podcast opinion laravel application part2 php7

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