Inversion of Control Container for PHP? [closed]

2019-01-16 12:50发布

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.

7条回答
我想做一个坏孩纸
2楼-- · 2019-01-16 13:31

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.

查看更多
看我几分像从前
3楼-- · 2019-01-16 13:31

Laravel 4 has the best IoC and DI framework. if you dont mind using a framework the Laravel 4 is the way to go

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-16 13:32

You might also want to try Ding (http://marcelog.github.com/Ding) which is modeled after Spring(tm) for Java. It is a complete inversion of control and dependency injection container, which also supports AOP

查看更多
混吃等死
5楼-- · 2019-01-16 13:32

PHP-DI is another dependency injection container.

It features dependency injection through annotations and minimal configuration, here is an example:

class Foo {
    /**
     * @Inject
     * @var Bar
     */
    private $bar;
}

It's very easy to use, and it integrates with Zend Framework for example.

(yes I do work on this framework)

查看更多
别忘想泡老子
6楼-- · 2019-01-16 13:51

What about the Symfony Dependency Injection or the PHP 5.3+ equivalent component from the symfony 2.0 project.

查看更多
我命由我不由天
7楼-- · 2019-01-16 13:53

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?

查看更多
登录 后发表回答