Pebble – more injection and less dependencies in PHP

Dependency Injection (DI) is hardly anything new. I see it as a must for Test Driven Development (TDD). The thing I like most about DI in Java is Autowired in Spring or javax.annotation.Resource, they way member variables are set “magically” and the exact details about creation and implementation is located elsewhere.

For PHP there are at least the following implementations related to Dependency Injection:

PHP-Dependency (Pd) works with @ annotation in the constructor comment, but why involve the constructor? And is a whole framework needed? PHP is not Java.

Pimple is very much a Dependency Injection Container, not so much about the injection. Simple, yes.

When it comes to Zend Framework 2 Dependency Injection I just can’t grasp how it simplifies anything. It seems to require a lot of boilerplate.

Unsatisfied with the above and a given a dose of NIH Syndrome, I decided to create my own DI system for PHP. After a bit of coding yesterday evening and night I named it Pebble and it is already on github! 🙂

My current requirements on Pebble are as follows:

  1. It must be possible to inject values of specific properties on class construction
  2. It must work nicely in Zend Framework 1.x
  3. It must not require any configuration files (and especially no XML)
  4. It must be a single .php file for the core implementation
  5. It must provide an open interface for extension and customization
  6. It must work nicely with PHPUnit (especially with the getMock method)
  7. It must work with autoloading of classes in PHP
  8. It is allowed to use PHP 5.3 features
  9. It is allowed to use @-based annotations in docComment, e.g. /** @something */

However, I have not yet used Pebble with PHPUnit, so I don’t know yet if that requirement holds!

Now is a good time for you to examine example1.php! The README is currently plain-text, I’ll format it later!

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.