PHPackages                             dmt-software/di-plug - 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. dmt-software/di-plug

ActiveLibrary

dmt-software/di-plug
====================

An PHP dependency container abstraction

0.3.2(2mo ago)01071MITPHPPHP &gt;=8.1

Since Mar 13Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/dmt-software/di-plug)[ Packagist](https://packagist.org/packages/dmt-software/di-plug)[ RSS](/packages/dmt-software-di-plug/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (16)Versions (6)Used By (1)

DI-Plug
=======

[](#di-plug)

Introduction
------------

[](#introduction)

[psr-11](https://www.php-fig.org/psr/psr-11/) introduced a standardized way for packages, libraries and frameworks to retrieve objects from containers. This package also allows adding dependencies to a container by a uniform interface without the use of a specific container implementation. This will help developers to access the dependency injection container to make installation of their packages easier.

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

[](#installation)

```
composer require dmt-software/di-plug
```

Usage
-----

[](#usage)

### Manual create the container

[](#manual-create-the-container)

```
use DMT\DependencyInjection\Adapters\PimpleAdapter;
use DMT\DependencyInjection\Container;
use Pimple\Container as PimpleContainer;

$container = new Container(new PimpleAdapter(new PimpleContainer()));
$container->set(SomeClass::class, fn() => new SomeClass($container->get(SomeDependency::class)));
```

### Autodetect

[](#autodetect)

Use the container builder to wrap your container instance within the `DMT\DependencyInjection\Container`.

```
use DMT\DependencyInjection\ContainerFactory;

/** @var object $supportedContainerInstance */
$factory = new ContainerFactory();
$container = $factory->createContainer($supportedContainerInstance);
$container->set(SomeClass::class, fn() => new SomeClass($container->get(SomeDependency::class)));
```

### Autodiscovery

[](#autodiscovery)

> NOTE: When another dependency uses a supported container, autodiscovery might end up using a different container than expected.

The code can discover the dependency container installed.

```
use DMT\DependencyInjection\ContainerFactory;

$factory = new ContainerFactory();
$container = $factory->createContainer();
$container->set(SomeClass::class, fn() => new SomeClass($container->get(SomeDependency::class)));
```

Concepts
--------

[](#concepts)

### Instances without registration

[](#instances-without-registration)

If the `Container::get()` is called with a className that is not present in the container will create a new instance for that class. This also counts for calls with made with constructor arguments.

callsetreturnsContainer::get(Some::class)falsenew instanceContainer::get(Some::class)truefrom dependencyContainer::get(Some::class, 12)truenew instance> NOTE: when the container creates a new instance it will NOT be set in the container. Not even when it is called with the same constructor arguments.

### Auto Inject Container

[](#auto-inject-container)

Instead of injection all the dependencies, one can choose to inject just the container and resolve the dependencies when needed. This can easily be achieved by using the `HasContainer` trait.

```
use DMT\DependencyInjection\Container;
use DMT\DependencyInjection\Traits\HasContainer;

class SomeClass
{
    use HasContainer;

    public function doSomething(): void
    {
        $dependency = $this->getContainer()->get(SomeDependency::class);
        $dependency->doSomething();
    }
}
```

This even works when the `HasContainer` is used within another trait, but just one level deep. Using the trait below f.i. enables `getTwigEngine()` call to retrieve the template engine in the parent class.

```
use DMT\DependencyInjection\Traits\HasContainer;
use Twig\Environment;

trait HasTwigEngine
{
    use HasContainer;

    public function getTwigEngine(): Environment
    {
        return $this->getContainer()->get(Environment::class);
    }
}
```

### ServiceProvider

[](#serviceprovider)

A service provider can be used to register or change dependencies in the container.

```
use DMT\DependencyInjection\Container;
use DMT\DependencyInjection\ServiceProviderInterface;
use Twig\Environment;
use Twig\Extension\StringLoaderExtension;

class MyServiceProvider implements ServiceProviderInterface
{
    /**
     * Register dependencies and ensure twig is enabled with string loader extension.
     */
    public function register(Container $container): void
    {
        if (!$container->has(Environment::class)) {
            $container->set(Environment::class, fn() => new Environment());
        }

        $env = $container->get(Environment::class);
        if (!$env->hasExtention(StringLoaderExtension::class)) {
            $env->addExtension(new StringLoaderExtension());
        }

        $container->set(MyClassInterface::class, fn() => new MyClass($container->get(Environment::class)));
    }
}
```

Supports
--------

[](#supports)

- [Aura dependency injection container](https://packagist.org/packages/aura/di)
- [Illuminate container](https://packagist.org/packages/illuminate/container)
- [League container](https://packagist.org/packages/league/container)
- [PHP-DI container](https://packagist.org/packages/php-di/php-di)
- [Pimple container](https://packagist.org/packages/pimple/pimple)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance87

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community9

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

Total

5

Last Release

65d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec6b7fbb4d231b5c2c76348cf3a13ec5e82c64a1826142f6ec0db1cf15db2873?d=identicon)[proggeler](/maintainers/proggeler)

---

Top Contributors

[![proggeler](https://avatars.githubusercontent.com/u/18281353?v=4)](https://github.com/proggeler "proggeler (31 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/dmt-software-di-plug/health.svg)

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

###  Alternatives

[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[api-platform/state

API Platform state interfaces

223.4M57](/packages/api-platform-state)[laminas/laminas-cli

Command-line interface for Laminas projects

563.7M54](/packages/laminas-laminas-cli)[neos/flow-development-collection

Flow packages in a joined repository for pull requests.

144179.3k3](/packages/neos-flow-development-collection)

PHPackages © 2026

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