FireDI – PHP Dependency Injection

About FireDI

FireDI is a dependency injection container built for PHP. It is like no other PHP DI Container available. It is a light weight and features automatic, constructor based, dependency resolution. When you need a new object from a class definition just simply ask for it. Any dependencies type hinted on the constructor will be resolved and injected before the class is instantiated into an object.

Features

  • Automatic constructor based dependency resolution. Dependencies can be resolve automatically for you by type hinting the object you expect to be injected in the constructor.
  • Circular dependency detection.
  • Automatic object caching. So that when you ask for an object more than once, it is provided without having to run through the process of dependency resolution.
  • Ability to define your own dependencies within the DI container. This works great for mocking dependencies within unit/integration tests.
  • Ability to define your own dependencies for the situation where you need to get a class with specific dependencies that are not defined with in the container.

Quick Demo

Let’s say you would like to get an instantiated object MyClass1. Well MyClass1 requires that you pass into its constructor MyClass2. FireDI will resolve MyClass2 and automatically inject it into MyClass1 and return the instantiated object MyClass1 to you.

// MyClass1 definition
class MyClass1
{
    public function __construct(MyClass2 $myClass2) {}
}

// MyClass2 definition
class MyClass2 {}

// instantiate firedi
$firedi = new UA1Labs\Fire\Di();

// obtain an object and have it's dependencies resolved for you
$myClass1 = $firedi->get('MyClass1');

Get FireDI

Get Answers

Report Issues