PHPackages                             pkj/dic - 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. pkj/dic

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

pkj/dic
=======

Dependency Injection Container.

05PHP

Since Nov 28Pushed 11y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

PHP - Dependency Injection Container
====================================

[](#php---dependency-injection-container)

Simple dependency injection container (DIC) or otherwise known as Inversion of Control (IoC). DIC helps you sort out dependencies for objects in a nice manner.

Example
-------

[](#example)

```
$di = new DependencyInjector();

class World {
    private $str;

    public function __construct($str) {
        $this->str = $str;
    }

    public function __toString () {
        return $this->str;
    }
}

$di->service('world', function ($string) {
    return new World($string);
}, ['World']);

$di->service('test', function ($number, $thing) {
    return "Hello $thing, this is a number: $number!";
}, [1337, '@world']);

echo $di->service('test');

```

Outputs:

```
Hello World, this is a number: 1337!
```

Documentation
-------------

[](#documentation)

### Services

[](#services)

Use the `service` method to create new services.

- *Argument 1:* The name of the service
- *Argument 2:* A callable that should return the value of the service when we want to fetch your service. Can return anything from a primitive value to a complex object.
- *Argument 3:* Values to pass into the `Argument 2`'s arguments. Use a string starting with `@` to inject a service, otherwise you can inject anything. Note that everything starting with a `@` is treated as a service.

### Configuration

[](#configuration)

It's possible to configure the `DependencyInjector` with the `config` method. You can also define custom global settings using `->config($key, $value)`.

Listed configuration below:

#### DependencyInjector::CONF\_STATIC\_ANALYSIS

[](#dependencyinjectorconf_static_analysis)

For convenience you can set `DependencyInjector::CONF_STATIC_ANALYSIS` to true, by doing this you don't need to specify arguments in the third argument using the `service` method.

Example:

```
// Enable static anlysis using reflection.
$di->config(DependencyInjector::CONF_STATIC_ANALYSIS, true);

// The following code:

$di->service('test', function ($world) {
    return "Hello $world!";
}, ['@world']);

// Can now become:

$di->service('test', function ($world) {
    return "Hello $world!";
});
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/88b748fa2f0dcacab307a6305e98032de7adb93f955bbaf3c6fe029a7369ac84?d=identicon)[peec](/maintainers/peec)

---

Top Contributors

[![peec](https://avatars.githubusercontent.com/u/131546?v=4)](https://github.com/peec "peec (1 commits)")

### Embed Badge

![Health badge](/badges/pkj-dic/health.svg)

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

###  Alternatives

[phpcollection/phpcollection

General-Purpose Collection Library for PHP

1.0k64.0M34](/packages/phpcollection-phpcollection)

PHPackages © 2026

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