PHPackages                             vakata/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. vakata/di

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

vakata/di
=========

PHP DI

3.0.6(8mo ago)06.2k↓78.2%MITPHPPHP &gt;=8.0.0

Since Jan 11Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/vakata/di)[ Packagist](https://packagist.org/packages/vakata/di)[ Docs](https://github.com/vakata/di)[ RSS](/packages/vakata-di/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (22)Used By (0)

DI
==

[](#di)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4dc8040f01f8a8b89608816a50575d1196938f8103d7516fc6e15b9bdba8d065/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76616b6174612f64692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vakata/di)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

PHP dependency injection / factory.

Install
-------

[](#install)

Via Composer

```
$ composer require vakata/di
```

Usage
-----

[](#usage)

```
namespace test;

$di = new \vakata\di\Container();

interface I { }
class A implements I {}
class B {
    public function __construct(I $instance) { }
}
class C {
    public function __construct($firstParam, $secondParam) { }
    public function test($arg = 1) { return 1; }
}

// this will register class A, and an alias I for class A as the class implements that interface
$di->register('\test\A');
$di->instance('\test\B'); // a B instance is created

// when registering you can prevent interfaces being added as aliases as adding the aliases manually
$di->register('\test\B', ['aliasedB']);

// you can also pass default constructor params, which can be named
$di->register('\test\C', null, ['secondParam' => 1, 2]);
$di->instance('\test\C'); // this will invoke \test\C::__construct(2,1);
$di->instance('\test\C', [2,4]); // this will invoke \test\C::__construct(2,4);

// you can also register instances:
$d = new D();
$di->register($d); // this is the same as \test\D

// you can also make sure that there is only one instance of a given class
$di->register('\some\class', ['aliases'], [/* default params */], true);

// aside from register and instance there is an invoke method
$di->invoke('\test\C', 'sum'); // returns 1

// you can also pass in arguments
$di->invoke('\test\C', 'sum', [2]); // returns 2

// and even constructor parameters
$di->invoke('\test\C', 'sum', [2], [5,6]);

// invoke works with instances too
$c1 = new C();
$di->invoke($c1, 'sum'); // returns 1
```

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [vakata](https://github.com/vakata)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance59

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity77

Established project with proven stability

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

Recently: every ~151 days

Total

21

Last Release

259d ago

Major Versions

1.0.8 → 2.0.02020-12-31

2.1.2 → 3.0.02024-02-20

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

2.1.0PHP &gt;=8.0.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/146052?v=4)[Ivan Bozhanov](/maintainers/vakata)[@vakata](https://github.com/vakata)

---

Top Contributors

[![vakata](https://avatars.githubusercontent.com/u/146052?v=4)](https://github.com/vakata "vakata (24 commits)")

---

Tags

vakataKVStore

### Embed Badge

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

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

###  Alternatives

[vakata/asn1

An ASN1 encoder / decoder

1628.6k3](/packages/vakata-asn1)

PHPackages © 2026

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