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

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

mouf/alias-container
====================

This package contains a really minimalist dependency injection container that can be used to create aliases of instances in existing containers.

v2.0.0(6y ago)51701MITPHP

Since Jan 31Pushed 6y ago17 watchersCompare

[ Source](https://github.com/thecodingmachine/alias-container)[ Packagist](https://packagist.org/packages/mouf/alias-container)[ Docs](http://mouf-php.com)[ RSS](/packages/mouf-alias-container/feed)WikiDiscussions 1.0 Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (1)

Alias-Container
===============

[](#alias-container)

[![Latest Stable Version](https://camo.githubusercontent.com/a1fba831bb8a595e0dff78f82f704f9fbcb2b632e863ea73af7b72b38acdc97f/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f616c6961732d636f6e7461696e65722f762f737461626c652e737667)](https://packagist.org/packages/mouf/alias-container)[![Latest Unstable Version](https://camo.githubusercontent.com/c77dfe6f6f9f589d5d2479bda21e6561ccba972e0c14eac1661e6aeed580986e/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f616c6961732d636f6e7461696e65722f762f756e737461626c652e737667)](https://packagist.org/packages/mouf/alias-container)[![License](https://camo.githubusercontent.com/40d7433eebb294d1fe2c7a2c6e1b732e29fba8801a5f4892b66b46efc70d23e8/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f616c6961732d636f6e7461696e65722f6c6963656e73652e737667)](https://packagist.org/packages/mouf/alias-container)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a5d7a87dca2c5891efcd31ec98d601f0caff61e04e1d78c56372dd505e3b6739/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f616c6961732d636f6e7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f623d312e30)](https://scrutinizer-ci.com/g/thecodingmachine/alias-container/?branch=1.0) [![SensioLabsInsight](https://camo.githubusercontent.com/59c103bcae75da1670837785fb6f1e735d22eff540e1e662c71bc769cc5ae265/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f30346639663236392d646234322d346133622d396366392d3166643431616163326538612f6d696e692e706e67)](https://insight.sensiolabs.com/projects/04f9f269-db42-4a3b-9cf9-1fd41aac2e8a)[![Build Status](https://camo.githubusercontent.com/43b27d3dc6ef0b86651776b61d066f021c2faf9f94166302fa1cfa62c88dbf16/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f616c6961732d636f6e7461696e65722e7376673f6272616e63683d312e30)](https://travis-ci.org/thecodingmachine/alias-container)[![Coverage Status](https://camo.githubusercontent.com/06715f87601f051da8c470b4c01346243f219743f294c76e811c5504733013d1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f616c6961732d636f6e7461696e65722f62616467652e7376673f6272616e63683d312e30)](https://coveralls.io/r/thecodingmachine/alias-container?branch=1.0)

This package contains a really minimalist dependency injection container that can be used to **create aliases** of instances in existing containers. Alias-container is compatible with [container-interop](https://github.com/container-interop/container-interop)and is meant to be used in conjunction with other containers. By itself, Alias-container does not store any entry. It can only be used to **create aliases of instances stored in other containers**.

You can use AliasContainer to add support for alias for any container that does not support this feature.

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

[](#installation)

Before using AliasContainer in your project, add it to your `composer.json` file:

```
$ ./composer.phar require mouf/alias-container ~1.0

```

Defining aliases in the container
---------------------------------

[](#defining-aliases-in-the-container)

Creating an alias container is a matter of creating an `AliasContainer` instance. The `AliasContainer` class takes 2 parameters:

- a [delegate-lookup container](https://github.com/container-interop/container-interop/blob/master/docs/Delegate-lookup.md) (e.g. the container we will look aliases into)
- the list of aliases, as an **associative array of strings**

```
use Mouf\AliasContainer;
use Interop\Container\ContainerInterface;

$aliasContainer = new AliasContainer($rootContainer, [
	"myAlias"=>"myInstance",
	"myAlias2"=>"myInstance2"
]);
```

The list of entries is an associative array.

- The key is the identifier of the alias to create
- The value is the identifier of the entry that will be aliased

Fetching entries from the container
-----------------------------------

[](#fetching-entries-from-the-container)

Fetching entries from the container is as simple as calling the `get` method:

```
$myInstance = $aliasContainer->get('myAlias');
```

Adding aliases to the container
-------------------------------

[](#adding-aliases-to-the-container)

You can add new aliases using the `set` method.

```
$aliasContainer->set('newAlias', 'myInstance');
```

Note that it is more efficient to initialize aliases in the container than calling recursively the `set` method.

Removing aliases from the container
-----------------------------------

[](#removing-aliases-from-the-container)

You can add new aliases using the `remove` method.

```
$aliasContainer->remove('myAlias');
```

Why the need for this package?
------------------------------

[](#why-the-need-for-this-package)

This package is part of a long-term effort to bring [interoperability between DI containers](https://github.com/container-interop/container-interop). The ultimate goal is to make sure that multiple containers can communicate together by sharing entries (one container might use an entry from another container, etc...)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Total

4

Last Release

2223d ago

Major Versions

v1.0.0 → 2.0.x-dev2020-04-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (8 commits)")

---

Tags

PSR-11dependency-injectiondialiasdecorator

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

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

Factory-Driven Dependency Injection Container

15955.1M694](/packages/laminas-laminas-servicemanager)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)

PHPackages © 2026

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