PHPackages                             emma/di - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. emma/di

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

emma/di
=======

A PHP 8.0+ Dependency Injection - Di - library. Easy to use and can Autowire any class/method/function. Similarly, you can autowire any config variables or values stored in the container.

v1.2.5(2y ago)1523GPL-2.0-onlyPHPPHP &gt;=8.0

Since May 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/debascoguy/Di)[ Packagist](https://packagist.org/packages/emma/di)[ RSS](/packages/emma-di/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (10)Used By (3)

Di - Dependency Injection
=========================

[](#di---dependency-injection)

A PHP 8.0+ Simple Dependency Injection - Di - library. Light weight and Easy to use. Autowire any class. Similarly, you can autowire any config variables or values stored in the container.

I am not going to bore you with lots of write-up to justify why you should or should not use this library as I strongly believe nobody says no to problem solving tools. So, here are the simplest example as it can be used to solve Di:

```
class Hello {

   protected $value = "Hello";

   public function __toString() {
       return $this->value;
   }
}

class World {

   protected $value = "World";

   public function __toString() {
       return $this->value;
   }
}

class HelloWorld {

   /**
    * See how we use the annotation to auto-inject the dependency class
    * @var Hello
    * @Inject Hello
    *
    * OR - use PHP 8 Attribute
    */
   #[Inject([Hello::class])]
   protected  Hello $hello;

   /**
    * @var World
    * @Inject World
    *
    * OR - use PHP 8 Attribute
    */
   #[Inject([World::class])]
   protected  World $world;

   /**
    * auto-wire by from CONFIG_VAR registered in container
    * @var string
    * @Inject (config='firstname')
    *
    * OR - use PHP 8 Attribute
    */
   #[Inject(['firstname'])]
   protected string $firstname;

   /**
    * auto-wire by from CONFIG_VAR registered in container
    * @var string
    * @Inject (config='lastname')
    *
    * OR - use PHP 8 Attribute
    */
   #[Inject(['lastname'])]
   protected string $lastname;

   /**
    * auto-wire by name registered in container
    * @var string
    * @Inject (name='email')
    *
    * OR - use PHP 8 Attribute
    */
   #[Inject(['email'])]
   protected string $email;

   public function getHello() {
       return $this->hello;
   }

   public function getWorld() {
       return $this->world;
   }

   /**
    * You can use any of the Standard inject annotation here. e.g:
    *
    * @Inject Hello $hello
    * @Inject World $world
    *
    * OR - use PHP 8 Attribute
    */
   #[Inject(['hello' => Hello::class, 'world' => World::class])]
   public function exampleForInjectingMethod(Hello $hello, World $world) {
       $this->hello = $hello;
       $this->world = $world;
   }

   public function __toString() {
       return $this->hello . " " . $this->world . " " . $this->firstname . " " . $this->lastname;
   }
}

use Emma\Di\Autowire\Autowire;
use ContainerManager;

/** @var AutowireInterface $autowire */
$autowire = $this->getContainer()->get(Autowire::class);

$container = $this->getContainer();
$container->register('CONFIG_VAR', ['firstname' => 'Ademola', 'lastname' => 'Aina']);
$container->register('email', 'debascoguy@gmail.com');

//All annotation with @Inject will be auto-wired into as dependency class
$helloWorld = $autowire->autowire(new HelloWorld());

//OR
$helloWorld = $autowire->autowire(HelloWorld::class);

echo $helloWorld->getHello();   //Output string "Hello"
echo $helloWorld->getWorld();   //Output string "World"
echo $helloWorld;               //Output string "Hello World Ademola Aina"

//BASIC AUTO-INJECT FUNCTION CALL
$helloWorld = new HelloWorld();

$methodsParameterMap = $callableParams = $autowire->autowire($helloWorld, "exampleForInjectingMethod");
//OR
$methodsParameterMap = $callableParams = $autowire->autowire(HelloWorld::class, "exampleForInjectingMethod");

$helloWorld->exampleForInjectingMethod($methodsParameterMap[0], $methodsParameterMap[1]);

echo $helloWorld->getHello();   //Output string "Hello"
echo $helloWorld->getWorld();   //Output string "World"
echo $helloWorld;               //Output string "Hello World Ademola Aina"

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~21 days

Recently: every ~39 days

Total

9

Last Release

913d ago

PHP version history (2 changes)v1.0.3PHP &gt;=7.0

v1.2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/17ecf1e99357556e97438ed0d7edbabada5380ff58e4a6a49cda3521f5a15637?d=identicon)[debascoguy](/maintainers/debascoguy)

---

Top Contributors

[![debascoguy](https://avatars.githubusercontent.com/u/12888833?v=4)](https://github.com/debascoguy "debascoguy (25 commits)")

### Embed Badge

![Health badge](/badges/emma-di/health.svg)

```
[![Health](https://phpackages.com/badges/emma-di/health.svg)](https://phpackages.com/packages/emma-di)
```

###  Alternatives

[classpreloader/classpreloader

Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case

37642.4M32](/packages/classpreloader-classpreloader)[swoole/ide-helper

IDE help files for Swoole.

5166.5M1.0k](/packages/swoole-ide-helper)[spatie/menu

Html menu generator

7592.9M6](/packages/spatie-menu)[ausi/slug-generator

Slug Generator

8002.2M22](/packages/ausi-slug-generator)[phpoffice/common

PHPOffice Common

23512.3M36](/packages/phpoffice-common)[kartik-v/dependent-dropdown

A multi level dependent dropdown JQuery plugin that allows nested dependencies.

1805.0M3](/packages/kartik-v-dependent-dropdown)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
