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. [Framework](/categories/framework)
4. /
5. waffle-commons/container

ActiveLibrary[Framework](/categories/framework)

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

Container component for Waffle framework.

0.1.0-beta4(2w ago)1991MITPHPPHP ^8.5CI passing

Since Nov 25Pushed 2w 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 today

READMEChangelog (10)Dependencies (42)Versions (25)Used By (1)

[![Discord](https://camo.githubusercontent.com/b30f41baece56d71f7f496f7e39fd33a2a096221c66c648b350dd4fe14276c2e/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3735353238383030313539323033333339313f6c6f676f3d646973636f7264)](https://discord.gg/eKgywnfXr2)[![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)

> **Release:** `0.1.0-beta4` | [`CHANGELOG.md`](./CHANGELOG.md)**PSR Compliance:** PSR-11 (`Psr\Container\ContainerInterface`)

A strict PSR-11 service container with reflection-based autowiring, circular-dependency detection, and worker-mode resettability. Core services (the PSR-11 `ContainerInterface` itself) are locked from override after registration.

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

[](#-installation)

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

🧱 Surface
---------

[](#-surface)

ClassRole`Waffle\Commons\Container\Container`The container. Implements `Waffle\Commons\Contracts\Container\ContainerInterface` (PSR-11 + `ResettableInterface`).`Waffle\Commons\Container\Autowire`Reflection-based autowiring helper used by `Container::build()` to resolve constructor parameters.`Waffle\Commons\Container\Exception\ContainerException`Thrown for retrieval / resolution failures.`Waffle\Commons\Container\Exception\NotFoundException`Thrown when `get($id)` cannot resolve the identifier.🚀 Usage
-------

[](#-usage)

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

$container = new Container([
    // Direct instance
    LoggerInterface::class => new StreamLogger(),

    // Class string — autowired via reflection on first get()
    UserService::class => UserService::class,

    // Factory closure
    'app.config' => static fn() => new Config(__DIR__ . '/config', 'prod'),
]);

$logger = $container->get(LoggerInterface::class);
$exists = $container->has(UserService::class);

$container->set('db.cache', new ArrayCache());
```

The exact public signature, verbatim from `Waffle\Commons\Contracts\Container\ContainerInterface`:

```
public function get(string $id): mixed;
public function has(string $id): bool;
public function set(string $id, object|callable|string $concrete): void;
public function reset(): void; // from ResettableInterface
```

🔁 Worker-mode reset
-------------------

[](#-worker-mode-reset)

`Container` implements `ResettableInterface`. After each request, the kernel calls `reset()` so the container drops its instance cache while keeping the registered definitions, preventing user-context leaks across FrankenPHP worker requests.

🛡️ Locked core services
-----------------------

[](#️-locked-core-services)

The constant `Container::CORE_SERVICES` lists identifiers that **must not** be redefined once registered. The PSR-11 `ContainerInterface` itself is in that list — any attempt to override it after the container is built throws `ContainerException`.

🔄 Circular-dependency detection
-------------------------------

[](#-circular-dependency-detection)

`Container::get($id)` tracks the resolution stack in `$resolving` and throws `ContainerException` if a cycle is detected before infinite recursion can occur.

🐘 PHP 8.5 features used
-----------------------

[](#-php-85-features-used)

- `final class Container` — no subclassing.
- Typed properties throughout.
- Typed constants for service registries: `private const CORE_SERVICES = [...];`.
- `#[\Override]` on every method that overrides PSR-11.

🧭 Architectural boundary (`mago guard`)
---------------------------------------

[](#-architectural-boundary-mago-guard)

An active dependency **perimeter** is enforced on every CI run by `vendor/bin/mago guard` (bundled into `composer mago`; zero baselines). The rules live in [`mago.toml`](./mago.toml) under `[guard.perimeter]` — a forbidden `use` statement fails the build, not a reviewer.

Production code under `Waffle\Commons\Container` may depend **only** on:

- `Waffle\Commons\Container\**` — itself
- `Waffle\Commons\Contracts\**` — the shared contracts package, the **only** Waffle dependency permitted
- `Psr\**` — PSR interfaces (PSR-11)
- `@global` + `Psl\**` — PHP core and the PHP Standard Library

Test code under `WaffleTests\Commons\Container` is unrestricted (`@all`). Structural rules are guarded too: interfaces must be named `*Interface`, `Exception\**` classes must end in `*Exception`, and any `Enum\**` namespace may hold only `enum` declarations.

Contract-first, component-agnostic by construction: components compose through `waffle-commons/contracts`, never directly through one another.

🧪 Testing
---------

[](#-testing)

```
docker exec -w /waffle-commons/container waffle-dev composer tests
```

📄 License
---------

[](#-license)

MIT — see [LICENSE.md](./LICENSE.md).

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance95

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community12

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

Recently: every ~5 days

Total

10

Last Release

19d 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 (81 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

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[bref/bref

Bref is a framework to write and deploy serverless PHP applications on AWS Lambda.

3.4k10.6M67](/packages/bref-bref)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M203](/packages/sulu-sulu)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M419](/packages/drupal-core-recommended)

PHPackages © 2026

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