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

ActiveLibrary

uma/dic
=======

A minimalistic PSR-11 container

v4.2.0(5mo ago)2021.9k↓37.5%3MITPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since May 3Pushed 1mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (12)Used By (3)

uma/dic
=======

[](#umadic)

[![CI](https://github.com/1ma/DIC/actions/workflows/phpunit.yml/badge.svg)](https://github.com/1ma/DIC/actions)[![Code Coverage](https://camo.githubusercontent.com/9e1678c6ee67b1e65c19999be0c60cc72118df965a7fbbec1f497e31320eac17/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f316d612f4449432f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/1ma/DIC/?branch=master)

A PSR-11 container focused on human readability and comprehension.

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

[](#installation)

```
$ composer require uma/dic:^4.0

```

Design Goals
------------

[](#design-goals)

### Simplicity

[](#simplicity)

A dependency injection container is a rather simple concept and its implementation should be simple, too.

### PSR-11 compliance

[](#psr-11-compliance)

It must implement the PSR-11 spec, and be usable wherever a PSR-11 container is to be expected.

### Setter

[](#setter)

It must have a standard way to add dependencies to the container as well as retrieve them. Using a Dependency Injection Container involves these two operations, not just getting them (I'm looking at you PSR-11).

To that end the `Container` class has a `set` method and also accepts an optional array of type `string => mixed` in its constructor, which is equivalent to calling `set($id, $entry)` with each of its key-value pairs.

Moreover, definitions have to be overridable, because definition overrides are a common approach in testing contexts.

```
$container = new UMA\DIC\Container([
  'host' => 'localhost',
  'port' => 8080
]);

$container->set('foo', 'bar');
$container->set('foo', 'baz');
var_dump($container->get('foo'));
// 'baz'
```

### Lazy loading

[](#lazy-loading)

It must be possible to register lazy services. These are services that are not instantiated until they are actually retrieved for the first time.

This library implements lazy services with anonymous functions. Whenever the container is asked for a service that is actually an anonymous function, that function is executed (passing the container itself as the first parameter) and the result is stored under the same id where the anonymous function used to be.

In addition, the container has a `resolved` method that returns whether a given service is an anonymous function or not. This can be useful when you need to assert whether a given service has been actually called (or not) on test code.

```
$container = new UMA\DIC\Container();
$container->set('dsn', '...');

// A database connection won't be made until/unless
// the 'db' service is fetched from the container
$container->set('db', static function(Psr\Container\ContainerInterface $c): \PDO {
  return new \PDO($c->get('dsn'));
});

var_dump($container->resolved('db'));
// false

$pdo = $container->get('db');

var_dump($container->resolved('db'));
// true
```

### Providers

[](#providers)

When a project involves large numbers of services these can be organized in Provider classes.

These classes implement `UMA\DIC\ServiceProvider` and receive an instance of the container in their `provide` method. They are then expected to register sets of related services in it. This concept is borrowed from [Pimple](https://github.com/silexphp/Pimple).

```
$container = new UMA\DIC\Container();
$container->register(new Project\DIC\Repositories());
$container->register(new Project\DIC\Controllers());
$container->register(new Project\DIC\Routes());
$container->register(new Project\DIC\DebugRoutes());
```

### Service Factories

[](#service-factories)

In a few niche cases it can be desirable to create a new instance of the service every time it's requested from the container.

Like lazy loading, service factories are implemented using anonymous functions. However, they are registered with the `factory` method instead of `set`.

```
$container = new UMA\DIC\Container();

// Normal lazy loaded service. Will always return the
// same object instance after running the Closure once.
$container->set('foo', static function(): \stdClass {
  return new \stdClass();
});

// Factory service. The second argument must be a Closure.
// The closure will run every time the service is requested.
$container->factory('bar', static function(): \stdClass {
  return new \stdClass();
});

// foo is always the same object instance.
var_dump($container->get('foo') === $container->get('foo'));
// true

// bar is a different object instance each time it's requested.
var_dump($container->get('bar') === $container->get('bar'));
// false
```

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance82

Actively maintained with recent releases

Popularity34

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

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

Recently: every ~431 days

Total

11

Last Release

157d ago

Major Versions

v1.0.3 → v2.0.02020-12-24

v2.0.1 → v3.0.02021-03-24

v3.0.1 → v4.0.02024-05-25

PHP version history (7 changes)v1.0.0PHP &gt;=7.1

v2.0.0PHP ^7.3.0 || ^7.4.0 || 8.0.0

v2.0.1PHP ^7.3.0 || ^7.4.0 || ^8.0.0

v3.0.1PHP ^7.3.0 || ^7.4.0 || ^8.0.0 || ^8.1.0

v4.0.0PHP ~8.2.0 || ~8.3.0

v4.1.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0

v4.2.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e9c44fd950318b0691210b9e372cfaae750d5d6a0b37500676ff636b3a58f1f?d=identicon)[1ma](/maintainers/1ma)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[neos/flow

Flow Application Framework

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

API Platform state interfaces

223.4M57](/packages/api-platform-state)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)[symfony/json-streamer

Provides powerful methods to read/write data structures from/into JSON streams.

14440.0k8](/packages/symfony-json-streamer)[rubix/server

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

632.3k](/packages/rubix-server)

PHPackages © 2026

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