<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Wed, 19 Jun 2013 20:35:53 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Reddit.com: Dependency injection in ZF2 and Symfony 2 are service locators]]></title>
      <guid>http://www.phpdeveloper.org/news/19468</guid>
      <link>http://www.phpdeveloper.org/news/19468</link>
      <description><![CDATA[<p>
On Reddit's PHP section there's a discussion happening about <a href="http://www.reddit.com/r/PHP/comments/1caidn/dependency_injection_in_zf2_and_symfony_2_are/"> dependency injection versus service locators</a> in two popular PHP frameworks - Zend Framework 2 and Symfony 2 (and how they're not really DI at all).
</p>
<blockquote>
Both ZF2 and Symfony 2 offer the same behavior: if I'm in a controller, and I want to use a service, I have to get it from the container with $this->get('my_service').
As such, the controller is not using DI, this is the service locator pattern. Controllers become more difficult to tests because of that, and they depend on the container now. I wonder why both frameworks didn't go further: why not treat controllers like services and use dependency injection on them. In other words: if a controller needs a service "A", then it should get it in the constructor, or through setter/property injection.
</blockquote>
<p>
The <a href="http://www.reddit.com/r/PHP/comments/1caidn/dependency_injection_in_zf2_and_symfony_2_are/">comments</a> talk some about the "controller from the DI container" idea, some other ways around the problem and some clarification as to what the frameworks are actually doing related to the container injection.
</p>
Link: http://www.reddit.com/r/PHP/comments/1caidn/dependency_injection_in_zf2_and_symfony_2_are]]></description>
      <pubDate>Tue, 16 Apr 2013 12:40:07 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPBuilder.com: Use Dice for Simplified PHP Dependency Injection]]></title>
      <guid>http://www.phpdeveloper.org/news/19428</guid>
      <link>http://www.phpdeveloper.org/news/19428</link>
      <description><![CDATA[<p>
On PHPBuilder.com there's a new tutorial showing how to <a href="http://www.phpbuilder.com/articles/application-architecture/design/use-dice-for-simplified-php-dependency-injection.html">use the Dice dependency injection container</a> to manage dependencies in your application.
</p>
<blockquote>
<a href="http://r.je/dice.html">Dice</a> is a Dependency Injection Container for PHP. It allows you to very quickly and simply use <a href="http://www.phpbuilder.com/columns/php-dependency-injection/Jason_Gilmore04292011.php3">Dependency Injection</a> techniques in your code with very minimal effort on your end. 
</blockquote>
<p>
The article talks some about the features of the Dice DIC and shares a simple introduction to its use in a more practical example. It uses constructor injection and type hinting to automatically handle the injections based on its current set of object references. 
</p>
<blockquote>
With Dice you don't have to worry about how the User accesses the Session object, you add it as a constructor parameter and it Just works. You don't need to reconfigure the container, you don't need to do anything at all. You just alter the constructor definition and everything is done for you.
</blockquote>
<p>
You can find more details about Dice in <a href="http://r.je/dice.html">this post</a> (including more examples of it in action and a link to it's repository <a href="https://github.com/TomBZombie/Dice">on github</a>.
</p>
Link: http://www.phpbuilder.com/articles/application-architecture/design/use-dice-for-simplified-php-dependency-injection.html]]></description>
      <pubDate>Mon, 08 Apr 2013 13:04:46 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Igor Wiedler: Stateless Services]]></title>
      <guid>http://www.phpdeveloper.org/news/19410</guid>
      <link>http://www.phpdeveloper.org/news/19410</link>
      <description><![CDATA[<p>
<i>Igor Wiedler</i> has a recent post to his site about creating <a href="https://igor.io/2013/03/31/stateless-services.html">stateless services</a>, specifically in the context of using a dependency injection container to manage the objects your application uses.
</p>
<blockquote>
As more frameworks and libraries, particularly in the PHP world, move towards adopting the Dependency Injection pattern they are all faced with the problem of bootstrapping their application and constructing the object graph. In many cases this is solved by a Dependency Injection Container (DIC). Such a container manages the creation of all the things. The things it manages are services. Or are they?
</blockquote>
<p>
He notes that, according to some of the principles of domain-driven design, "services" should be stateless - the results of calls to the service shouldn't alter it, it should only depend on the values passed in. He goes on to put this into the context of a DIC and gives an example of the "request service" (and how it violates the DDD principles of statelessness). He talks some about scopes (dependencies) and mutable services. He talks about methods to get around these issues with the "request" instance, ultimately coming to the conclusion that event listeners might be the way to go.
</p>
Link: https://igor.io/2013/03/31/stateless-services.html]]></description>
      <pubDate>Thu, 04 Apr 2013 10:41:50 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Matt Frost: Dependency Injection Container Question]]></title>
      <guid>http://www.phpdeveloper.org/news/19192</guid>
      <link>http://www.phpdeveloper.org/news/19192</link>
      <description><![CDATA[<p>
In his <a href="http://shortwhitebaldguy.com/blog/2013/02/dependency-injection-container-question">latest post</a> <i>Matt Frost</i> takes a look at dependency injection. He thinks out loud about some of the common uses for it but wonders if there's a middle ground for using a DIC and injecting manual dependencies.
</p>
<blockquote>
The question I have is what if a dependency in one class also has a dependency? To illustrate what I mean, here's an example with some code to follow. [...] I'm not really concerned about the code here as much as I am about the concept that I'm trying to illustrate, in order to use a dependency injection container for this scenario.
</blockquote>
<p>
In his example code, he shows a "DBAuthMethod" class that extends the "AuthMethod" interface and an "Auth" class that requires an instance of "AuthMethod" as a constructor parameter. He wonders about constructor versus setter injection and thinks that a mix of the two may not be the best structure for the code. 
</p>
<blockquote>
I just can wrap my mind around a scenario where you could ONLY use a DIC, and if you can't use the concept exclusively what benefit is there to using it?
</blockquote>
<p>
Have any suggestions to share? <a href="http://shortwhitebaldguy.com/blog/2013/02/dependency-injection-container-question">Let him know</a> - this is a problem more and more developers run into as DIC becomes more widely used.
</p>]]></description>
      <pubDate>Mon, 18 Feb 2013 09:26:17 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Logging with PSR-3 to Improve Reusability]]></title>
      <guid>http://www.phpdeveloper.org/news/19148</guid>
      <link>http://www.phpdeveloper.org/news/19148</link>
      <description><![CDATA[<p>
On PHPMaster.com <i>Patrick Mulvey</i> has written up a new  tutorial looking at <a href="http://phpmaster.com/logging-with-psr-3-to-improve-reusability/">using the PSR-3 logging structure</a> to make a basic logger for your application.
</p>
<blockquote>
Logging is one of the most ubiquitous tasks encountered in PHP. We use logs to track error messages, record important events, and debug problems with our code. In any PHP project, the code is likely to be full of calls to a logging library which handles these actions for us. [...] To promote compatibility between logging libraries, the PHP-FIG group recently released PRS-3, a common interface for logger objects. In this article, I'll discuss how the logger interface defined by PSR-3 allows us to write reusable code that isn't dependent on any particular logging implementation.
</blockquote>
<p>
He includes a quick introduction to the PSR-3 format, how to get the files you'll need to use it (via Composer). He includes some sample code showing how to make the basic email class with a logger injected for use. Since the Monolog logging project follows the PSR-3 format, it's an easy drop-in option. He also talks about using PSR-3 to avoid having logger dependencies with the "LoggerInterface". There's also a bit at the end of the tutorial showing you how to use the Adapter design pattern to "proxy" the logging calls to the class via a PSR-3 interface.
</p>]]></description>
      <pubDate>Thu, 07 Feb 2013 10:22:26 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[NetTuts.com: How to Write Code That Embraces Change]]></title>
      <guid>http://www.phpdeveloper.org/news/19132</guid>
      <link>http://www.phpdeveloper.org/news/19132</link>
      <description><![CDATA[<p>
On NetTuts.com today there's a great new article about how to <a href="http://net.tutsplus.com/tutorials/how-to-write-code-that-embraces-change/">write code that embraces change</a> and can be easily updated and reconfigured due to a decoupled nature and use of good OOP concepts.
</p>
<blockquote>
Writing code, which is easy to change is the Holy Grail of programming. Welcome to programming nirvana! But things are much more difficult in reality: source code is difficult to understand, dependencies point in countless directions, coupling is annoying, and you soon feel the heat of programming hell. In this tutorial, we will discuss a few principles, techniques and ideas that will help you write code that is easy to change.
</blockquote>
<p>
He covers some of the good OOP principles to think about when developing - like cohesion, orthogonality and coupling (via class methods, polymorphism, dependency injection or interfaces). He spends some time looking at the <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> development principles and how you can implement each of them in some sample code. He also talks some about high level design and how the separation of concerns can help make your code easier to maintain and change.
</p>]]></description>
      <pubDate>Mon, 04 Feb 2013 13:18:58 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Dependency Injection with Pimple]]></title>
      <guid>http://www.phpdeveloper.org/news/19103</guid>
      <link>http://www.phpdeveloper.org/news/19103</link>
      <description><![CDATA[<p>
On PHPMaster.com there's a new tutorial showing you <a href="http://phpmaster.com/dependency-injection-with-pimple/">how to use Pimple</a> (the <a href="http://pimple.sensiolabs.org/">dependency injection container</a> from the Symfony folks) in your application to manage objects and resources.
</p>
<blockquote>
In application development, we try to create independent modules so that we can reuse code in future projects. But, it's difficult to create completely independent modules which provide useful functionality; their dependencies can cause maintenance nightmares unless they are managed properly. This is where Dependency Injection comes in handy, as it gives us the ability to inject the dependencies our code needs to function properly without hard coding them into the modules.
</blockquote>
<p>
They start with a look at the problem with working with "concerete dependencies", ones that are hard-coded into your classes making them not only hard to test but potentially difficult to maintain. They include an example of this (a "SocialFeeds" class and friends) and then one of two ways to fix the situation. They start with using constructor-based injection, injecting the Twitter service into the main feeds object. They also talk about another method - setter-based injection - where the objects are injected via specific methods on the object. 
</p>
<p>
As a third alternative, though, they get to using Pimple to manage the objects, making it easier to inject just the one resource into your classes and extract the objects you need from there. There's also a bit of "advanced" usage of Pimple showing the use of the "share" and "extend" methods.
</p>]]></description>
      <pubDate>Tue, 29 Jan 2013 09:37:50 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Gonzalo Ayuso: Handling several DBALs in Symfony2 through the Dependency Injection with PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/19044</guid>
      <link>http://www.phpdeveloper.org/news/19044</link>
      <description><![CDATA[<p>
<i>Gonzalo Ayuso</i> has a second post in his series looking at using the Symfony2 dependency injection container with Doctrine functionality. In his <a href="http://phpdeveloper.org/news/19007">previous post</a> he talked about sharing PDO connections via the DIC. In <a href="http://gonzalo123.com/2013/01/14/handling-several-dbal-database-connections-in-symfony2-through-the-dependency-injection-container-with-php/">this latest one</a> it's focused on the sharing of DBALs from Doctrine.
</p>
<blockquote>
OK. We can handle PDOs connections inside a Symfony2 application, but what happens if we prefer DBAL. As we know DBAL is built over PDO and adds a set of "extra" features to our database connection. It's something like PDO with steroids.
</blockquote>
<p>
He includes the (PHP) configuration to set up the DBAL and the YAML definition to set it up in the DIC's configuration. As an update to the post, he also points out a bundle for Symfony2 that lets Doctrine do this natively - check out <a href="https://github.com/doctrine/DoctrineBundle/blob/master/Resources/doc/configuration.rst#doctrine-dbal-configuration">this documentation</a> on github.
</p>]]></description>
      <pubDate>Wed, 16 Jan 2013 10:47:32 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Anthony Ferrara: Programming With Anthony - Dependency Injection]]></title>
      <guid>http://www.phpdeveloper.org/news/19018</guid>
      <link>http://www.phpdeveloper.org/news/19018</link>
      <description><![CDATA[<p>
<i>Anthony Ferrara</i> has posted his <a href="http://blog.ircmaxell.com/2013/01/dependency-injection-programming-with.html">latest video tutorial</a> in <a href="https://www.youtube.com/playlist?list=PLM-218uGSX3DQ3KsB5NJnuOqPqc5CW2kW&feature=view_all">his series</a>, this time covering dependency injection (mostly the concepts, not the implementation).
</p>
<blockquote>
This week, we're going to talk about the topic of Dependency Injection in Object oriented code (specifically PHP). You don't need a fancy container to do it, it's actually quite simple to do manually! 
</blockquote>
<p>
He also talks some about the difference between a dependency injection container and a service locator. This is just the latest in his video series - he has others covering things like <a href="https://www.youtube.com/watch?v=nLinqtCfhKY">prepared statements</a>, <a href="https://www.youtube.com/watch?v=RLmuFlDygn0">encryption</a> and <a href="https://www.youtube.com/watch?v=_YZIBWQr_yk">references in PHP</a>.
</p>]]></description>
      <pubDate>Thu, 10 Jan 2013 09:08:57 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Freek Lijten: SOLID - The D is for Dependency Inversion Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/18980</guid>
      <link>http://www.phpdeveloper.org/news/18980</link>
      <description><![CDATA[<p>
<i>Freek Lijten</i> has posted the <a href="http://www.freeklijten.nl/home/2013/01/02/SOLID-The-D-is-for-Dependency-Inversion-Principle">last article in his series</a> looking at the <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> development principles, this time looking at "D", the Dependency Inversion Principle.
</p>
<blockquote>
The DIP deals with avoiding mixing different levels of abstraction in your code. In this article we will explore the last of these principles in depth. [...] I want to show you how depending on abstractions makes our lives easier in a larger example. Since we're going to be loading, updating and storing bikes a lot in our application I would like an Api for that. It would not be such a good idea to write the same queries or perform the same validation over and over.
</blockquote>
<p>
He includes two examples - one a bit simplistic involving bike storage and another more complex that uses interfaces to define structure and object injection rather than passing data around. He also tries to help clear up some of the confusion that might happen around dependency inversion and dependency injection.
</p>]]></description>
      <pubDate>Wed, 02 Jan 2013 10:25:46 -0600</pubDate>
    </item>
  </channel>
</rss>
