PHPackages                             yuloh/container - 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. yuloh/container

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

yuloh/container
===============

A lightweight container-interop compatible DI container

v1.0.0(9y ago)173.3k↓100%1MITPHPPHP &gt;=5.4.0

Since Apr 11Pushed 9y ago2 watchersCompare

[ Source](https://github.com/matt-allan/container)[ Packagist](https://packagist.org/packages/yuloh/container)[ Docs](https://github.com/yuloh/container)[ RSS](/packages/yuloh-container/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Container
=========

[](#container)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4b35fbc2b8447aa7cb1926ee07d0aba7ca1f357b390cc27f59eabc5ac88ba8e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79756c6f682f636f6e7461696e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yuloh/container)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/dcba903f74c08e4a7ae174eebee3eefd51f4dd791bcc6547cb3d4dd73356936d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f79756c6f682f636f6e7461696e65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/yuloh/container)

Container is a lightweight dependency injection container. It's compatible with the [PSR-11 container interface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md), so you can use it with lots of different projects out of the box.

The container is really simple; It's basically an array of identifier =&gt; callable mappings, and the callable is invoked to get the resulting object.

New to dependency injection and containers? I wrote a [blog post](http://mattallan.org/2016/dependency-injection-containers/) explaining dependency injection and how this container works.

This package is compliant with PSR-1, PSR-2, PSR-4, and PSR-11.

Install
-------

[](#install)

Via Composer

```
$ composer require yuloh/container
```

Usage
-----

[](#usage)

### Adding Entries

[](#adding-entries)

Adding an entry to the container is really simple. Just specify the identifier as the first argument, and a callable as the second argument.

```
use Yuloh\Container\Container;

$container = new Container();

$container->set(Psr\Log\LoggerInterface::class, function () {
    $logger = new Monolog\Logger();
    $logger->pushHandler(new StreamHandler('error.log'));
    return $logger;
});
```

The closure will receive the container as it's only argument, so you can use the container to resolve the dependencies of your entry.

```
$container->set('db', function ($container) {
    $db = new Database();
    $logger = $container->get(Psr\Log\LoggerInterface::class);
    $db->setLogger($logger);
    return $db;
});
```

All entries are shared (singletons), which means an entry will be resolved once and reused for subsequent calls.

### Getting Entries

[](#getting-entries)

To check if an entry exists, use `has`. To get an entry, use `get`. If you are just retrieving entries you can typehint `Psr\Container\ContainerInterface` instead of the actual Container.

```
if ($container->has('db')) {
    $db = $container->get('db');
}
```

Why Another Container?
----------------------

[](#why-another-container)

There are **a lot** of containers out there. I was working on a project and wanted a lightweight default container and couldn't find what I wanted. This container:

- Implements container-interop.
- Supports PHP 5.4+
- Supports adding entries at runtime.
- Is incredibly lightweight, with the bare minimum of code to support the first 3 goals.

Testing
-------

[](#testing)

```
$ composer test
$ composer cs
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

2

Last Release

3306d ago

Major Versions

v0.1.0 → v1.0.02017-04-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/a2687baf734ad8beb4dcc84d936ab41a500412e0aad55ab5a15a2205cacee15f?d=identicon)[matt-allan](/maintainers/matt-allan)

---

Tags

container-interopdependency-injectionpsr-11containeryuloh

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/yuloh-container/health.svg)

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

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[league/container

A fast and intuitive dependency injection container.

86387.8M342](/packages/league-container)[php-di/php-di

The dependency injection container for humans

2.8k48.9M991](/packages/php-di-php-di)[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

356968.3k58](/packages/aura-di)[league/tactician-container

Tactician integration for any container implementing PSR-11

7710.1M23](/packages/league-tactician-container)[acclimate/container

Provides adapters for various third-party service containers.

219390.6k15](/packages/acclimate-container)

PHPackages © 2026

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