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

ActiveLibrary[Framework](/categories/framework)

codeia/di-senpai
================

DI framework; implements container-interop

v0.1.5(9y ago)0691BSD-2-ClausePHPPHP &gt;=5.5

Since Jul 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/monzee/di-senpai)[ Packagist](https://packagist.org/packages/codeia/di-senpai)[ RSS](/packages/codeia-di-senpai/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (7)Used By (1)

DI-senpai
=========

[](#di-senpai)

Auto resolving dependency injector. Build your object graphs programmatically.

Installation
------------

[](#installation)

```
$ composer require codeia/di-senpai

```

Usage
-----

[](#usage)

Create a container:

```
class Module {
    function auth() {
        return new biz\Auth();
    }

    function security(ContainerInterface $c) {
        return new biz\Acl($c->get(SecurityPolicy::class));
    }

    function acl() {
        return new stub\AllowEveryone();
    }

    function users(ContainerInterface $c) {
        return new db\UserRepository($c->get(PDO::class));
    }

    function db() {
        return new PDO('sqlite::memory:');
    }
}

$provided = (new ObjectGraphBuilder(new Module))->withScoped([
    // map the module method names to their return types
    // you need to do this for interfaces; AutoResolve can handle the concrete
    // dependencies
    'auth' => [Authenticator::class],
    'security' => [Authorization::class],
    'acl' => [SecurityPolicy::class],
    'users' => [UserRepository::class],
    'db' => [PDO::class],
])->build();
$container = new AutoResolve($provided);
```

> You can also use any `Psr\Container\ContainerInterface` impl, but `AutoResolve` is quite useful and is what makes `Senpai` work its magic. You can wrap a `ContainerInterface` in an `AutoResolve`r then use that.

> `AutoResolve` and `ObjectGraph` both implement `ContainerInterface`, so you can use them in other frameworks that can take them, like `zend-expressive`.

Call your senpai:

```
class LoginController {
    // must use FQCNs in the annotations

    /** @var site\service\Authenticator */
    private $auth;

    /** @var site\service\UserRepository */
    private $users;

    /** @var site\service\Authorization */
    private $checker;

    function __construct(Senpai $pls) {
        $pls->inject($this, Senpai::NO);
    }

    function isFullyUsable() {
        return !empty($this->auth)
            && !empty($this->users)
            && !empty($this->checker);
    }
}
```

Build your object and their privates will be populated:

> Leave out the second argument to `inject()` if you only want to inject public members.

```
$loginController = $container->get(LoginController::class);
$loginController->isFullyUsable();
```

- Only the object's members are injected. The dependencies' insides are not touched.
- No method injection is done. I don't believe setter injection should be a thing.

WARNING
-------

[](#warning)

This ties your classes to the DI framework! **AVOID THIS IF YOU CAN!** This severely limits the reusability of your classes. I myself only use this on classes that I probably won't ever reuse (like controllers) and only if they have a lot of dependencies (5 is my threshold).

Other legitimate uses are in frameworks where you don't have control over the instantiation and only provides hooks for your own code. Like activities in Android. Don't know if there are any frameworks that still work like that, it seems that lambdas are all the rage these days. Although again, I only recommend it when you have 5 or more dependencies to populate.

Even so, the `AutoResolve` and `ObjectGraph` classes are still handy can be used on their own.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Recently: every ~70 days

Total

6

Last Release

3359d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/55887?v=4)[Mon Zafra](/maintainers/monzee)[@monzee](https://github.com/monzee)

---

Top Contributors

[![monzee](https://avatars.githubusercontent.com/u/55887?v=4)](https://github.com/monzee "monzee (10 commits)")

---

Tags

container-interopobject graphdimodulecomponentauto resolveprovisionservice locatorcontainerscomposable

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M19.7k](/packages/laravel-framework)[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k13](/packages/tempest-framework)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M407](/packages/drupal-core-recommended)[mouf/picotainer

This package contains a really minimalist dependency injection container compatible with container-interop.

16191.5k11](/packages/mouf-picotainer)[mouf/pimple-interop

This project is a very simple extension to the Pimple microframework. It adds to Pimple compatibility with the container-interop APIs.

102.5M2](/packages/mouf-pimple-interop)

PHPackages © 2026

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