PHPackages                             phetit/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. phetit/container

Abandoned → [phetit/dependency-injection](/?search=phetit%2Fdependency-injection)Library[Utility &amp; Helpers](/categories/utility)

phetit/container
================

A simple PHP dependency injection container

v0.7.0(2y ago)010MITPHPPHP ^8.1

Since Jul 11Pushed 2y ago1 watchersCompare

[ Source](https://github.com/phetit/dependency-injection)[ Packagist](https://packagist.org/packages/phetit/container)[ Docs](https://github.com/phetit/dependency-injection)[ RSS](/packages/phetit-container/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (7)Dependencies (7)Versions (8)Used By (0)

[![GitHub release (latest SemVer)](https://camo.githubusercontent.com/d447369cd509e9b22de4939d0b0b4673d363f39c654fba57615b20f078332909/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f7068657469742f646570656e64656e63792d696e6a656374696f6e3f646973706c61795f6e616d653d74616726736f72743d73656d766572)](https://github.com/phetit/dependency-injection/releases/latest)[![Packagist](https://camo.githubusercontent.com/4c147bb6dba181e478e605d9af0dbfd7b2d063a5bbbe59b0774f305dfc18b192/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068657469742f646570656e64656e63792d696e6a656374696f6e)](https://packagist.org/packages/phetit/dependency-injection)[![Packagist PHP Version](https://camo.githubusercontent.com/89bab68ff105bbff2a8962e466a33704949308a40e8f13ce240e19b69f89debd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f7068657469742f646570656e64656e63792d696e6a656374696f6e2f7068703f636f6c6f723d366537316134)](https://camo.githubusercontent.com/89bab68ff105bbff2a8962e466a33704949308a40e8f13ce240e19b69f89debd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f7068657469742f646570656e64656e63792d696e6a656374696f6e2f7068703f636f6c6f723d366537316134)[![tests](https://github.com/phetit/dependency-injection/actions/workflows/tests.yml/badge.svg)](https://github.com/phetit/dependency-injection/actions/workflows/tests.yml?query=branch%3Amain)[![GitHub](https://camo.githubusercontent.com/44ff7bdae4db306978355f846906712ec515b70155150cd92387ff73b72070db/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068657469742f646570656e64656e63792d696e6a656374696f6e)](https://github.com/phetit/dependency-injection/blob/main/LICENSE)

Phetit Container
================

[](#phetit-container)

A simple PHP dependency injection container.

This package is an implementation of [PSR-11](https://www.php-fig.org/psr/psr-11/) container interface, and follows the [Semantic Versioning](https://semver.org/spec/v2.0.0.html) specification.

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

[](#installation)

You can install it using [composer](https://getcomposer.org/):

```
composer require phetit/dependency-injection
```

Usage
-----

[](#usage)

Create an instance of `ContainerBuilder` class.

```
use Phetit\DependencyInjection\ContainerBuilder;

$container = new ContainerBuilder();
```

### Register a service

[](#register-a-service)

You can register a service using the `register($id, $resolver)` method, and passing the `id` (string) and the `resolver` (a closure).

```
$container->register('foo', fn() => 'bar');
```

### Retrieving the service

[](#retrieving-the-service)

You can retrieve registered services using the `get($id)` method:

```
$foo = $container->get('foo');
// $foo === 'bar'
```

### Non shared services

[](#non-shared-services)

By default all services are shared. This means that services are resolved only the first time `get($id)` method is called. So in following calls you'll get the same object.

```
$container->register('service', fn() => new Service());

$serviceOne = $container->get('service'); // Service object
$serviceTwo = $container->get('service'); // Service object

// $serviceOne === $serviceTwo => true
```

In order to get a new instance on every call, you need to use the `factory()` method:

```
$container->factory('service', fn() => new Service());

$serviceOne = $container->get('service'); // Service object
$serviceTwo = $container->get('service'); // Service object

// $serviceOne === $serviceTwo => false
```

### Parameters

[](#parameters)

You can register parameters using `parameter()` method:

```
$container->parameter('foo', 'bar');
$container->parameter('closure', fn() => new Service());

$container->get('foo'); // 'bar'

// Parameters are not resolved
$closure = $container->get('closure'); // $closure = fn() => new Service()
$service = $closure(); // 'Service object'
```

### Accessing container from a service

[](#accessing-container-from-a-service)

Container object is injected to service resolvers, so you can access other entries defined in the container:

```
$container->parameter('db_dns', 'mysql:dbname=testdb;host=127.0.0.1');
$container->parameter('db_user', 'dbuser');
$container->parameter('db_pass', 'dbpass');

$container->register('db', fn(Container $c) => new PDO(
    $c->get('db_dns'),
    $c->get('db_user'),
    $c->get('db_pass'),
));
```

Contributing
------------

[](#contributing)

Refer to [CONTRIBUTING](./CONTRIBUTING.md) for information.

License
-------

[](#license)

[MIT](https://github.com/phetit/dependency-injection/blob/main/LICENSE)

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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.

###  Release Activity

Cadence

Every ~2 days

Total

7

Last Release

1062d ago

### Community

Maintainers

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

---

Top Contributors

[![lombervid](https://avatars.githubusercontent.com/u/3432651?v=4)](https://github.com/lombervid "lombervid (60 commits)")

---

Tags

componentcomposer-librarycomposer-packagedependency-injection-containerdi-containerphpphp-componentphp-libraryphp-packagedi containerdependency-injectiondidependency injection container

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k447.1M9.0k](/packages/symfony-dependency-injection)[aura/di

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

352982.2k60](/packages/aura-di)[level-2/dice

A minimalist Dependency injection container (DIC) for PHP. Please note: 3.0+ is only compatible with PHP 7.0. The 2.0 branch is compatbile with PHP 5.6.

437773.0k19](/packages/level-2-dice)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

562565.8k42](/packages/ecotone-ecotone)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3512.4M3](/packages/mrclay-props-dic)[infocyph/intermix

A lightweight PHP DI container, invoker, serializer, and utility toolkit.

137.3k1](/packages/infocyph-intermix)

PHPackages © 2026

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