PHPackages                             vpa/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. [Framework](/categories/framework)
4. /
5. vpa/di

ActiveLibrary[Framework](/categories/framework)

vpa/di
======

The simple DI implementation for PHP 8.x with using Attributes #\[Injectable\]

v0.4(3y ago)21952AGPL-3.0-or-laterPHPPHP &gt;=8.0

Since Aug 14Pushed 3y ago2 watchersCompare

[ Source](https://github.com/zolll23/DI)[ Packagist](https://packagist.org/packages/vpa/di)[ Docs](https://github.com/zolll23/di)[ RSS](/packages/vpa-di/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (10)Used By (2)

DI
==

[](#di)

[![Latest Stable Version](https://camo.githubusercontent.com/c60aaeca9234d0cd4c7e6831f1ae4257369fc3325d97199787e9dd1776763860/687474703a2f2f706f7365722e707567782e6f72672f7670612f64692f76)](https://packagist.org/packages/vpa/di)[![Total Downloads](https://camo.githubusercontent.com/fd22eae41257025dc423a148f44eb9eb6e30de4615418e0ecb5c6d95980ad1a4/687474703a2f2f706f7365722e707567782e6f72672f7670612f64692f646f776e6c6f616473)](https://packagist.org/packages/vpa/di)[![Latest Unstable Version](https://camo.githubusercontent.com/01d2db7ec72552cac0f92bd8fe66ea5d0283410ff64fc6cf97788f4adb134b4f/687474703a2f2f706f7365722e707567782e6f72672f7670612f64692f762f756e737461626c65)](https://packagist.org/packages/vpa/di)[![License](https://camo.githubusercontent.com/5db96783ae36f3468bcd591b197c881ae7a06cdb3f374de88330719a9787263d/687474703a2f2f706f7365722e707567782e6f72672f7670612f64692f6c6963656e7365)](https://packagist.org/packages/vpa/di)[![PHP Version Require](https://camo.githubusercontent.com/3fe41b02654ecc9cbd1162f117cf66a189b397f58b313b8e37237ae58d612d8b/687474703a2f2f706f7365722e707567782e6f72672f7670612f64692f726571756972652f706870)](https://packagist.org/packages/vpa/di)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/601bc81f3b4de3db97b392d2b964421ea63c3b0fb9162c41d66f0c33091e87ca/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a6f6c6c6c32332f44492f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/zolll23/DI/?branch=main)[![Code Coverage](https://camo.githubusercontent.com/3fd72b2c9aa329eefe0312165b22ff6922ae42ea890b62d9535d0ef3ac4f9fc7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a6f6c6c6c32332f44492f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/zolll23/DI/?branch=main)[![Build Status](https://camo.githubusercontent.com/93560dbcac1b59bf3e75621bcb2518b4c3b1c4f709c2e480ef9684b7728d44a9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a6f6c6c6c32332f44492f6261646765732f6275696c642e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/zolll23/DI/build-status/main)[![Code Intelligence Status](https://camo.githubusercontent.com/44ef454ea31b01f6c14fb94767e61d57b8b927f6c7cde300100908f0fb07bd4c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a6f6c6c6c32332f44492f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d61696e)](https://scrutinizer-ci.com/code-intelligence)

Dependency Injection pattern implementation PSR-11 (Psr\\Container\\ContainerInterface) for PHP 8.x

To specify the classes for which this pattern can be applied, attributes are used, support for which was added to PHP 8. This implementation allows you to fully control for which classes you can apply DI, just like Angular or NestJS does.

**Install**

```
composer require vpa/di

```

**Example**:

```
require_once(__DIR__ . '/../vendor/autoload.php');

use VPA\DI\Container;
use VPA\DI\Injectable;

#[Injectable]
class A {

    function __construct() {}
    function echo () {
        print("\nThis is Sparta!\n");
    }
}

#[Injectable]
class B {

    function __construct(protected A $a) {}
    function echo () {
        $this->a->echo();
    }
}

class C {

    function __construct(protected A $a) {}
    function echo () {
        $this->a->echo();
    }
}

$di = new Container();
$di->registerContainers();
$b = $di->get(B::class); // returns instance of class B
$b->echo();
$c = $di->get(C::class); // returns exception (class C not tagged as Injectable)
$c->echo();

```

You can add aliased classes manually, but the declaration of these classes must still have the #\[Injecatble\] tag.

```
$di = new Container();
$di->registerContainers(['E'=>A::class]);
$e = $di->get('E');
echo $e instanceof A; // returns true

```

If your class has a constructor with parameters (and the types of those parameters are not an object) you can pass those parameters as the second parameter of the get method as an array:

```
#[Injectable]
class A {
    function __construct() {}
}
#[Injectable]
class B {

    function __construct(protected A $a, private int $x, private int $y) {}
}

$di = new Container();
$di->registerContainers();
$b = $di->get(B::class,['x'=>10,'y'=>20]);

```

**Bubble Propagation for attribute Injectable**

In version 0.2.0 added method `setBubblePropagation(bool $bubblePropogation)`(default is true) which specifies whether parent classes should be checked for the presence of an attribute *Injectable*. This allows you to not set the attribute *Injectable* to all children that should be DI.

Example:

```
// In versions less 0.2.0 code below returns Exception, in version 0.2.0 and great - will return the desired class
#[Injectable]
class A {}
class B extends A {} // this class is not marked with the attribute Injectable
$di = new Container();
$di->registerContainers();
$b = $di->get(B::class);

```

Similar to the previous point, DI supports bubble propagation for interfaces as well:

```
// In versions less 0.2.0 code below returns Exception, in version 0.2.0 and great - will return the desired class
#[Injectable]
interface A {}
class B implements A {} // this class is not marked with the attribute Injectable
$di = new Container();
$di->registerContainers();
$b = $di->get(B::class);

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

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 ~25 days

Recently: every ~36 days

Total

7

Last Release

1223d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/523331c06e4907fb980d7f07b8c3e5ab44d1fc3924819f87f13d4bbe6f8528f3?d=identicon)[Zolll23](/maintainers/Zolll23)

---

Top Contributors

[![zolll23](https://avatars.githubusercontent.com/u/3510681?v=4)](https://github.com/zolll23 "zolll23 (73 commits)")

---

Tags

dependencyinjectionattributesphp 8.xInjectable

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[yiisoft/di

Yii DI container

2351.2M100](/packages/yiisoft-di)[laravel-lang/common

Easily connect the necessary language packs to the application

1463.1M22](/packages/laravel-lang-common)[marwanalsoltany/mighty

The last validation library you will ever need!

591.3k](/packages/marwanalsoltany-mighty)

PHPackages © 2026

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