views:

2648

answers:

5

I am trying to code TDD style in PHP and one of my biggest stumbling blocks (other than lack of a decent IDE) is that I have to make my own hacked together IoC container just to inject all my mock objects properly.

Has anyone used an Ioc container in php? All I've been able to find is PHP IOC on the ever-annoying phpclasses.org and it seems to have almost no documentation and not much of a following.

+2  A: 

I played with some DI Frameworks for PHP, but I haven't used one in production. Have some links:

  1. http://www.stubbles.net/ which I think is the oldest I tried
  2. http://php.xjconf.net/
  3. FLOW3 - I belive this one will become a very nice framework (its beta right now)

You mentioned you would use it for TDD - so maybe have a look at Dependency Injection for Unit Tests in PHP

crono
+2  A: 

Hey! I good day! I was the author of the PHP IOC in PHPclass.org however, I don't update the libraries there anymore. If you are still interested in working the framework you can download the file and complete documentation at:

http://www.raincreativelab.com/dl/php_ioc/

If you have questions just email me at [email protected]

Thanks,

+1  A: 

I have been working on a PHP IoC/DI Container named Substrate for the last six months. It is still very much a work in progress but it has been deployed in production for a month and a half and has been working pretty well so far.

Substrate is inspired by Spring Framework, but written with the strengths and limitations of PHP in mind. The documentation is pretty minimal at this point, but there is some sample code, including a unit testing example. Is this something that you think you might be able to use for TDD?

Beau Simensen
+4  A: 

Phemto is being developed again, and looks quite promising IMHO.

A few other similar projects, that you might want to look at:

bucket (Disclaimer: I'm the principal author of this one)

The php-port of picocontainer, has been around for a long time. I don't think it's being actively deveoped any more, but on the other hand, I believe that it's quite stable. It's been a long time since I looked at it though.

A rather new project, I recently stumbled upon is Crafty. Not sure how many people uses it though.

I'm also watching sphicy, which looks interesting.

troelskn
Download link for Crafty is broken. I spoke to the author, he said its a dead project, newer versions of PHP broke it due to changes in PHP reflection api.
Frank Schwieterman
OK - I've updated the post accordingly.
troelskn
A: 

At the risk of resurrecting something very old, I've build a very simple IoC container for PHP 5.3+. It is available here:

http://bitbucket.org/chrisjsmith/phpioc

ChrisSmith..zzZZ