PHPackages                             slince/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. slince/di

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

slince/di
=========

A flexible dependency injection container

3.2.3(2y ago)20260.4k—4.3%56MITPHPPHP &gt;=7.4CI failing

Since Oct 8Pushed 2y ago3 watchersCompare

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

READMEChangelogDependencies (3)Versions (15)Used By (6)

Dependency Injection Container
==============================

[](#dependency-injection-container)

[![Build Status](https://camo.githubusercontent.com/d47458e1cfc776f5f564375a4fcb86f1c40dd9121b2f0c46b5d543f62c8fffae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736c696e63652f64692f746573742e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/slince/di/actions)[![Coverage Status](https://camo.githubusercontent.com/b100bb24bb9b89bc885c1b811ba17d1baa81d6d86c79386c5015508c1b14f6b1/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f736c696e63652f64692e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/slince/di)[![Total Downloads](https://camo.githubusercontent.com/8651ec45a7df4dd6e2978f92273402e491fe280fddfec6b10a3b07a655d4529c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736c696e63652f64692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/slince/di)[![Latest Stable Version](https://camo.githubusercontent.com/04bb7c5d2c7412bee16cf1992d7cc3eff65456a47a02e99cc1c6efd2cc9d5dce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736c696e63652f64692e7376673f7374796c653d666c61742d737175617265266c6162656c3d737461626c65)](https://packagist.org/packages/slince/di)[![Scrutinizer](https://camo.githubusercontent.com/68baaf844c91c03d4992a7d911bb004c014dec76138c2bad57999c1dfdf76bfe/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f736c696e63652f64692e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/slince/di/?branch=master)

This package is a flexible IOC container for PHP with a focus on being lightweight and fast as well as requiring as little configuration as possible. It is an implementation of [PSR-11](https://github.com/container-interop/fig-standards/blob/master/proposed/container.md)

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

[](#installation)

Install via composer.

```
{
    "require": {
        "slince/di": "^3.0"
    }
}
```

Alternatively, require package use composer cli:

```
composer require slince/di ^3.0
```

Usage
-----

[](#usage)

Container is dependency injection container. It allows you to implement the dependency injection design pattern meaning that you can decouple your class dependencies and have the container inject them where they are needed.

```
namespace Acme;

class Foo
{
   /**
     * @var \Acme\Bar
     */
    public $bar;

    /**
     * Construct.
     */
    public function __construct(Bar $bar)
    {
        $this->bar = $bar;
    }
}

class Bar
{
    public $foo;
    public $baz;

    public function __construct($foo, $baz)
    {
        $this->foo = $foo;
        $this->baz = $baz;
    }
}

$container = new Slince\Di\Container();

$container->register(Acme\Foo::class);
$foo = $container->get(Acme\Foo::class);

var_dump($foo instanceof Acme\Foo);      // true
var_dump($foo->bar instanceof Acme\Bar); // true
```

### Make Service References

[](#make-service-references)

```
$container->register('bar', Acme\Bar::class);
$container->register('foo', Acme\Foo::class)
    ->addArgument(new Slince\Di\Reference('bar')); //refer to 'bar'

var_dump($container->get('bar') === $container->get('foo')->bar));    // true
```

### Use a Factory to Create Services

[](#use-a-factory-to-create-services)

Suppose you have a factory that configures and returns a new `NewsletterManager` object by calling the static `createNewsletterManager()` method:

```
class NewsletterManagerStaticFactory
{
    public static function createNewsletterManager($parameter)
    {
        $newsletterManager = new NewsletterManager($parameter);

        // ...

        return $newsletterManager;
    }
}
```

```
// call the static method
$container->register(
    NewsletterManager::class,
    array(NewsletterManagerStaticFactory::class, 'createNewsletterManager')
)->addArgument('foo');
```

If your factory is not using a static function to configure and create your service, but a regular method, you can instantiate the factory itself as a service too.

```
// call a method on the specified factory service
$container->register(NewsletterManager::class, [
    new Reference(NewsletterManagerFactory::class),
    'createNewsletterManager'
]);
```

### Create Service Aliases

[](#create-service-aliases)

```
$container->register(Acme\Foo::class);
$container->setAlias('foo-alias', Acme\Foo::class);
$foo = $container->get('foo-alias');

var_dump($foo instanceof Acme\Foo);      // true
```

### Configure container

[](#configure-container)

- Singleton

```
$container->setDefaults([
    'share' => false
]);
$container->register('foo', Acme\Foo::class);
var_dump($container->get('foo') === $container->get('foo'));      // false
```

- Autowiring

```
$container->setDefaults([
    'autowire' => false,
]);
$container->register('foo', Acme\Foo::class)
    ->addArgument(new Acme\Bar());  // You have to provide $bar

var_dump($container->get('foo') instanceof Acme\Foo::class);  // true
```

### Container Parameters

[](#container-parameters)

```
$container->setParameters([
    'foo' => 'hello',
    'bar' => [
        'baz' => 'world'
    ]
]);

$container->register('bar', Acme\Bar::class)
     ->setArguments([
        'foo' => $container->getParameter('foo'),
        'baz' => $container->getParameter('bar.baz')
    ]);

$bar = $container->get('bar');
var_dump($bar->foo);  // hello
var_dump($bar->bar); // world
```

### Work with Service Tags

[](#work-with-service-tags)

```
$container->register('foo')->addTag('my.tag', array('hello' => 'world'));

$serviceIds = $container->findTaggedServiceIds('my.tag');

foreach ($serviceIds as $serviceId => $tags) {
    foreach ($tags as $tag) {
        echo $tag['hello'];
    }
}
```

License
-------

[](#license)

The MIT license. See [MIT](https://opensource.org/licenses/MIT)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 97.9% 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 ~203 days

Recently: every ~319 days

Total

13

Last Release

1067d ago

Major Versions

1.1.1 → 2.0.02017-05-26

2.0.0 → 3.0.02018-09-21

PHP version history (4 changes)1.0.0PHP &gt;=5.5.9

2.0.0PHP &gt;=5.6.0

3.2.0PHP &gt;=7.2.5

3.2.1PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3785826?v=4)[Tao](/maintainers/slince)[@slince](https://github.com/slince)

---

Top Contributors

[![slince](https://avatars.githubusercontent.com/u/3785826?v=4)](https://github.com/slince "slince (95 commits)")[![jtojnar](https://avatars.githubusercontent.com/u/705123?v=4)](https://github.com/jtojnar "jtojnar (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

containerdependency-injectiondiinjectionioc-containerphppsr-11containerPSR-11injectiondependency-injectiondiioc

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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