PHPackages                             mouf/picotainer - 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. [Framework](/categories/framework)
4. /
5. mouf/picotainer

ActiveLibrary[Framework](/categories/framework)

mouf/picotainer
===============

This package contains a really minimalist dependency injection container compatible with container-interop.

v1.1.0(9y ago)16189.8k—8.3%6[1 PRs](https://github.com/thecodingmachine/picotainer/pulls)11MITPHP

Since Jan 21Pushed 9y ago19 watchersCompare

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

READMEChangelog (2)Dependencies (4)Versions (5)Used By (11)

Picotainer
==========

[](#picotainer)

[![Latest Stable Version](https://camo.githubusercontent.com/527863933dc9180ebe0d7014d71092a5b524eb6925a7d0e8da13f272f80b6e42/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7069636f7461696e65722f762f737461626c652e737667)](https://packagist.org/packages/mouf/picotainer)[![Latest Unstable Version](https://camo.githubusercontent.com/02131052c240b07c466a697892da7694e55126a09ce985b710d874941a862e06/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7069636f7461696e65722f762f756e737461626c652e737667)](https://packagist.org/packages/mouf/picotainer)[![License](https://camo.githubusercontent.com/2f67b8502478d9c8d3903d9eca704ef04551176db41df3444f03e5cd1349e83b/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7069636f7461696e65722f6c6963656e73652e737667)](https://packagist.org/packages/mouf/picotainer)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3848971897e7689adbac8180751cd94665f44bba7f9f147142fac2c519f177a4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f7069636f7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f623d312e30)](https://scrutinizer-ci.com/g/thecodingmachine/picotainer/?branch=1.0)[![SensioLabsInsight](https://camo.githubusercontent.com/d41a18f20dcd20749c999d2208692ef0f5bacfa0d22ce3234de8fdf3a1a3a133/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33616334336561632d646365632d343936612d396530662d3566653832663862333832342f6d696e692e706e67)](https://insight.sensiolabs.com/projects/3ac43eac-dcec-496a-9e0f-5fe82f8b3824)[![Build Status](https://camo.githubusercontent.com/9d4aeb02356e0e0fcf005958bff1a5e793812899129bdfc1c7fbacdd04603f1f/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f7069636f7461696e65722e7376673f6272616e63683d312e30)](https://travis-ci.org/thecodingmachine/picotainer)[![Coverage Status](https://camo.githubusercontent.com/fa2194b0f1effb3d0b097e14976e4567116ccca5ff30ac78ab993bcf38f9c40a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f7069636f7461696e65722f62616467652e7376673f6272616e63683d312e30)](https://coveralls.io/r/thecodingmachine/picotainer?branch=1.0)

This package contains a really minimalist dependency injection container (24 lines of code!) compatible with [container-interop](https://github.com/container-interop/container-interop) (supports ContainerInterface and delegate lookup feature). It is also, therefore, compatible with [PSR-11](https://github.com/php-fig/fig-standards/blob/master/proposed/container.md), the FIG container standard.

Picotainer is heavily influenced by the [Pimple DI container](http://pimple.sensiolabs.org/). Think about it as a Pimple container with even less features, and ContainerInterop compatibility.

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

[](#installation)

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

```
$ ./composer.phar require mouf/picotainer ~1.0

```

Storing entries in the container
--------------------------------

[](#storing-entries-in-the-container)

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

- the list of entries, as an **array of anonymous functions**
- an optional [delegate-lookup container](https://github.com/container-interop/container-interop/blob/master/docs/Delegate-lookup.md)

```
use Mouf\Picotainer\Picotainer;
use Psr\Container\ContainerInterface;

$container = new Picotainer([
	"myInstance"=>function(ContainerInterface $container) {
		return new MyInstance();
	},
	"myOtherInstance"=>function(ContainerInterface $container) {
		return new MyOtherInstance($container->get('myInstance'));
	}
	"myParameter"=>function(ContainerInterface $container) {
		return MY_CONSTANT;
	}
], $rootContainer);
```

The list of entries is an associative array.

- The key is the name of the entry in the container
- The value is an **anonymous function** that will return the entry

The entry can be anything (an object, a scalar value, a resource, etc...)

The **anonymous function** must accept one parameter: the container on which dependencies will be fetched. The container is the "delegate-lookup container" if it was passed as the second argument of the constructor, or the Picotainer instance itself if no delegate lookup container was passed.

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

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

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

```
$myInstance = $container->get('myInstance');
```

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

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 78.3% 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 ~194 days

Total

5

Last Release

3358d ago

### 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 (18 commits)")[![Rayne](https://avatars.githubusercontent.com/u/1098733?v=4)](https://github.com/Rayne "Rayne (2 commits)")[![Sam-Burns](https://avatars.githubusercontent.com/u/6594039?v=4)](https://github.com/Sam-Burns "Sam-Burns (2 commits)")[![xhuberty](https://avatars.githubusercontent.com/u/8350192?v=4)](https://github.com/xhuberty "xhuberty (1 commits)")

---

Tags

container-interopdependency-injectiondi

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[mouf/pimple-interop

This project is a very simple extension to the Pimple microframework. It adds to Pimple compatibility with the container-interop APIs.

102.4M2](/packages/mouf-pimple-interop)[yiisoft/injector

PSR-11 compatible injector. Executes a callable and makes an instances by injecting dependencies from a given DI container.

942.8M38](/packages/yiisoft-injector)[mouf/mouf

The Mouf PHP framework: an open-source PHP framework providing an easy way to download, install, use and reuse components, with a graphical user interface.

55146.0k17](/packages/mouf-mouf)[joomla/di

Joomla DI Package

15391.2k11](/packages/joomla-di)

PHPackages © 2026

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