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

ActiveLibrary

waffle-commons/container
========================

Container component for Waffle framework.

0.1.0-alpha4(4mo ago)169[5 PRs](https://github.com/waffle-commons/container/pulls)1MITPHPPHP ^8.5CI passing

Since Nov 25Pushed 3mo agoCompare

[ Source](https://github.com/waffle-commons/container)[ Packagist](https://packagist.org/packages/waffle-commons/container)[ RSS](/packages/waffle-commons-container/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (12)Used By (1)

[![PHP Version Require](https://camo.githubusercontent.com/cf5ce2f2b6b514c9f692acdc7dcdeed97d80308a9613b14af38819a5a199d5dd/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f636f6e7461696e65722f726571756972652f706870)](https://packagist.org/packages/waffle-commons/container)[![PHP CI](https://github.com/waffle-commons/container/actions/workflows/main.yml/badge.svg)](https://github.com/waffle-commons/container/actions/workflows/main.yml)[![codecov](https://camo.githubusercontent.com/574c6424f31f763e8d30526bc48c99dc4be74815753372384d03fc83e51fb7e6/68747470733a2f2f636f6465636f762e696f2f67682f776166666c652d636f6d6d6f6e732f636f6e7461696e65722f67726170682f62616467652e7376673f746f6b656e3d64373461633632612d373837322d343033352d386238622d626363336166313939316530)](https://codecov.io/gh/waffle-commons/container)[![Latest Stable Version](https://camo.githubusercontent.com/54e0e11074f6ca0d16e7ad09ad2f8bfbd001c8b9430ddf8c2288bd0926fc0409/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f636f6e7461696e65722f76)](https://packagist.org/packages/waffle-commons/container)[![Latest Unstable Version](https://camo.githubusercontent.com/6f5496a2fcad6eed7197a1b5f1b70e0471b4baa930f09b77a176f2a89eec9404/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f636f6e7461696e65722f762f756e737461626c65)](https://packagist.org/packages/waffle-commons/container)[![Total Downloads](https://camo.githubusercontent.com/51b78e8bb9a33938c79d67bf34b098b7ce5142ffdfdf761383142bc34c0db652/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776166666c652d636f6d6d6f6e732f636f6e7461696e65722e737667)](https://packagist.org/packages/waffle-commons/container)[![Packagist License](https://camo.githubusercontent.com/78c381f251b177d57e9a47ac25d20f7e28353d004323f6a426b78d677eb95f3a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776166666c652d636f6d6d6f6e732f636f6e7461696e6572)](https://github.com/waffle-commons/container/blob/main/LICENSE.md)

Waffle Container Component
==========================

[](#waffle-container-component)

A lightweight, strict, and fully compliant PSR-11 Dependency Injection Container implementation for the Waffle Framework.

📦 Installation
--------------

[](#-installation)

```
composer require waffle-commons/container
```

🚀 Usage
-------

[](#-usage)

### Basic Usage

[](#basic-usage)

```
use Waffle\Commons\Container\Container;

$container = new Container();

// Register a simple value
$container->set('api_key', 'secret-123');

// Register a closure (lazy loading)
$container->set('database', function () {
    return new DatabaseConnection('localhost', 'root', 'password');
});

// Register a service
$container->set(MyService::class, new MyService());

// Retrieve services
$apiKey = $container->get('api_key');
$db = $container->get('database');
$service = $container->get(MyService::class);
```

### Autowiring

[](#autowiring)

The container supports automatic dependency resolution (autowiring) for concrete classes.

```
class Database { ... }

class UserRepository {
    public function __construct(private Database $db) {}
}

// Automatically resolves Database dependency
$repo = $container->get(UserRepository::class);
```

### Advanced Autowiring

[](#advanced-autowiring)

The container handles complex cases:

- **Default Values:** If a constructor parameter has a default value (e.g., `int $limit = 10`), it is used if no other value is found.
- **Nullable Types:** If a dependency is not found but the parameter is nullable (e.g., `?Logger $logger`), `null` is injected.
- **Recursion:** It can resolve chains like Controller -&gt; Service -&gt; Repository -&gt; Database -&gt; Config.

### Exceptions

[](#exceptions)

The component throws PSR-11 compliant exceptions:

- `Waffle\Commons\Container\Exception\NotFoundException`: Thrown when a requested identifier is not found and cannot be autowired.
- `Waffle\Commons\Container\Exception\ContainerException`: Thrown for general errors, such as:

    - Circular dependencies.
    - Uninstantiable classes (abstract classes, interfaces without implementation).
    - Unresolvable parameters (primitive types without default values).

### PSR-11 Compliance

[](#psr-11-compliance)

This container implements `Psr\Container\ContainerInterface`, making it compatible with any library that consumes PSR-11 containers.

This component provides a robust foundation for managing dependencies with powerful features like autowiring and circular dependency detection, while adhering strictly to PHP standards.

Features
--------

[](#features)

- **PSR-11 Compliance:** Fully implements `Psr\Container\ContainerInterface`.
- **Autowiring:** Automatically resolves dependencies for classes.
- **Interface Binding:** Bind interfaces to concrete implementations.
- **Factory Support:** Register closures as factories for complex services.
- **Circular Dependency Detection:** Throws an exception if a circular dependency is detected.
- **PSR-11 Compliant:** Fully compatible with the PHP Standard Recommendation.

Testing
-------

[](#testing)

To run the tests, use the following command:

```
composer tests
```

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

[](#contributing)

Contributions are welcome! Please refer to [CONTRIBUTING.md](./CONTRIBUTING.md) for details.

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE.md](./LICENSE.md) file for details.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance80

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

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

Total

3

Last Release

133d ago

PHP version history (2 changes)0.1.0-alpha1PHP ^8.4

0.1.0-alpha4PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/34a7557a3fb23aaf788ca3892b9b7efdf96e753264bafd0599153c9e8a921316?d=identicon)[LesliePetrimaux](/maintainers/LesliePetrimaux)

---

Top Contributors

[![supa-chayajin](https://avatars.githubusercontent.com/u/695448?v=4)](https://github.com/supa-chayajin "supa-chayajin (29 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  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)
