Alex Rivera | Logout

Guice like dependency injection frameworks in PHP

Asked 2012-02-19T10:20:40.120
17

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.

Edit
Report

2 Answers

9

(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.

answered 2012-04-05T05:37:56.580
2

Check out

rg\injektor is a sophisticated dependency injection container for PHP that was inspired by Guice. Unlike other reflection based containers rg\injektor includes a factory class generator that you can use to prevent the use of reflection on production.

It features Constructor Injection, Property Injection, Provider Classes, Object Management, Named Injection and a couple more things. It is unit-tested and available via Composer.

answered 2013-01-08T13:19:37.497

Your Answer