Guice喜欢PHP中的依赖注入框架 [英] Guice like dependency injection frameworks in PHP

查看:129
本文介绍了Guice喜欢PHP中的依赖注入框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中是否有任何Guice类似或类似的依赖注入框架?如果PHP中没有任何良好的依赖注入框架?



我必须在PHP中实现与Java中相同的代码,我在Java项目中使用Guice。因此,如果使用类似的框架,那么实现PHP版本会更容易。

解决方案

(发布我的评论作为回复) / p>

看看我的Guice的克隆名为 Sharbat (表示果汁)。该API与Guice相同。



几乎所有你需要的东西:




  • 构造函数注入(不需要@Inject注释)

  • 字段注入(不管可见性,使用@Inject(FooBar))

  • 方法注入(无论可见性如何,需要@Inject注释)

  • 提供者注入对于通过@InjectProvider(T = FooBar)的字段,通过@Provider(T = FooBar,param = fooBarProvider)的方法

  • 范围(可以实现自定义一个)

  • AOP (方法拦截器)

  • 循环依赖



请参阅自述文件以了解使用情况。


Are there any Guice like or similar dependency injection frameworks in PHP? If not are there any good dependency injection frameworks in PHP?

I have to implement same code in PHP what I have implemented in Java and I use Guice in my Java project. So it would be easier to implement PHP version, if it used similar framework.

解决方案

(Posting my comment as a response)

Have a look at my clone of Guice named Sharbat (means juice). The API is quite the same as Guice's.

It has pretty much everything you need:

  • Constructor injection (does not require @Inject annotation)
  • Field injection (regardless of visibility, using @Inject(FooBar))
  • Method injection (regardless of visibility, requires @Inject annotation)
  • Provider injection (for fields via @InjectProvider(T=FooBar), for methods via @Provider(T=FooBar, param=fooBarProvider)
  • Scopes (possible to implement a custom one)
  • AOP (method interceptors)
  • Circular dependencies

See the readme file for example usage.

这篇关于Guice喜欢PHP中的依赖注入框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆