Category: Web Design Tweets/ReTweets

Simple PHP Dependency Injection with Interfaces Example

   |   By  |  No comments

I created this graphic as a simple way to visualize dependency injection, unit testing and the use of php interfaces. The interface provides the “agreement/contract” between the implementations and  class \ControllerForExample. You can see that $httpClient can be any one of the implementations. \ControllerForExample doesn’t need to know the details of each implementation, only that the contract/implementation is valid.

View Full Size Graphic
php dependency injection and interfaces

Reflecting on 2013 Madison PHP Conference

   |   By  |  No comments

We are looking forward to attending Madison’s PHP Conference coming up in just a few days. I thought I would take a moment to reflect on last year’s conference and some of my highlights.

There was a great discussion on Composer and the use of for dependency management. Often times a software project has a list of dependencies upon which the project depends. Composer allows the developer to manage these dependencies using a json file (composer.json). A simple composer.json file might include a few specific dependencies at specific versions. Previously PEAR was used to handle software installation, but Composer has simplified and expanded dependency management.

There was another talk on moving from Legacy code to Modern code. This was an exciting discussion on refactoring code, unit testing and continuous integration. This was exciting, heady stuff! The writing of unit tests during refactoring made sense, and we will strive to tackle this daunting task on Legacy projects. Unit tests are essentially tests against one’s code. We make certain assumptions that X function/method should return Y. Unit tests ensure that these assumptions don’t break when refactoring code. There are many cases for using unit tests right away and PHPUnit has great documentation on useage.

Well, these were just two of the many discussions we attended last year. We are excited to attend this year’s 2014 conference at the Alliant Energy Center in Madison.