Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inversion of Control Container for PHP? [closed]

Tags:

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.

like image 741
George Mauer Avatar asked Sep 09 '08 14:09

George Mauer


People also ask

What is inversion of control in PHP?

Inversion of control (IOC) defines the way objects are used, but it does not specify how to create them. IOC defines the relationship between the high-level class and detail class, where the high-level class depends on detail class.

What is IoC container PHP?

An IoC container is a singleton Class(can only have 1 instance instantiated at any given time) where the specific way of instantiating objects of those class for this project can be registered.

What is a benefit of Laravel's IoC container?

Understanding and using the IoC container is a crucial part in mastering our craft, as it is the core part of a Laravel application. IoC container is a powerful tool for managing class dependencies. It has the power to automatically resolve classes without configuration.

What is the use of IoC container?

The IoC container that is also known as a DI Container is a framework for implementing automatic dependency injection very effectively. It manages the complete object creation and its lifetime, as well as it also injects the dependencies into the classes.


2 Answers

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

like image 60
crono Avatar answered Oct 05 '22 10:10

crono


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.

like image 33
troelskn Avatar answered Oct 05 '22 11:10

troelskn