PHPackages                             phpnomad/php-di-integration - 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. phpnomad/php-di-integration

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phpnomad/php-di-integration
===========================

PHP-DI integration for PHPNomad — compilable container, config repo, and registry backed by PHP-DI.

v1.0.0(1mo ago)00MITPHPPHP &gt;=8.2

Since May 6Pushed 1mo agoCompare

[ Source](https://github.com/phpnomad/php-di-integration)[ Packagist](https://packagist.org/packages/phpnomad/php-di-integration)[ RSS](/packages/phpnomad-php-di-integration/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (9)Versions (2)Used By (0)

PHP-DI Integration for PHPNomad
===============================

[](#php-di-integration-for-phpnomad)

PHP-DI-backed implementations of PHPNomad's `InstanceProvider`/`HasBindings`, `ConfigStrategy`, and `Registry` interfaces. An opt-in upgrade for consumers that want compilable, fast resolution while preserving PHPNomad's runtime extensibility.

Why
---

[](#why)

PHPNomad ships with an intentionally minimal default container. For distributed plugins (WordPress installs, etc.) where boot tax compounds across requests, this integration swaps in PHP-DI with build-time compilation — emitting a plain PHP class that opcache loads for free, eliminating per-request reflection cost.

The trade is a vendor dependency on `php-di/php-di` and a build-step that emits the compiled container. The runtime API matches PHPNomad's existing contract, so consumer code that already uses `InstanceProvider`, `HasBindings`, `ConfigStrategy`, or the `Registry` traits doesn't change.

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

[](#installation)

```
composer require phpnomad/php-di-integration
```

Usage
-----

[](#usage)

### As a suite (most common)

[](#as-a-suite-most-common)

Add the suite Initializer to your bootstrapper:

```
use PHPNomad\Integrations\PhpDi\Container\CompiledContainerLoader;
use PHPNomad\Integrations\PhpDi\Initializer as PhpDiInitializer;
use PHPNomad\Loader\Bootstrapper;

$container = CompiledContainerLoader::load($tier); // tier identifies the compiled artifact
(new Bootstrapper(
    $container,
    new PhpDiInitializer(),    // Container + Config + Registry sub-initializers
    new YourCoreInitializer(),
    // ...
))->load();
```

`CompiledContainerLoader::load($tier)` returns a `PhpDiContainer` wrapping either a build-time-compiled `\DI\Container` subclass (fast path) or a runtime-built `\DI\ContainerBuilder` (fallback when no compiled artifact is present). The runtime path is identical to non-compiled PHP-DI behavior.

### Piecemeal composition

[](#piecemeal-composition)

Power users that only want one of the three concerns can compose sub-initializers directly. Container must come first since Config and Registry depend on `InstanceProvider`:

```
use PHPNomad\Integrations\PhpDi\Container\Initializer as ContainerInitializer;
use PHPNomad\Integrations\PhpDi\Config\Initializer as ConfigInitializer;

(new Bootstrapper(
    $container,
    new ContainerInitializer(),
    new ConfigInitializer(),
    // skip Registry — keep PHPNomad's simple registry impl
    new YourCoreInitializer(),
))->load();
```

### Build-time compilation

[](#build-time-compilation)

Wire `Compiler::compileForTier()` into your build step. Run it after `composer install` (and after any vendor-prefixing step like Strauss) so the compiled output references runtime class names correctly:

```
use PHPNomad\Integrations\PhpDi\Container\Compiler;

$initializers = [
    new \PHPNomad\Integrations\PhpDi\Initializer(),
    new YourCoreInitializer(),
    // ...recurse into Loaders to flatten sub-initializers...
];

Compiler::compileForTier(
    tier:      'lite',
    outDir:    __DIR__ . '/build/lib/Compiled/PhpDiContainer',
    initializers: $initializers,
);
```

This emits a class at `/Lite.php` that the runtime loader will prefer over the runtime-built container. Per-tier compilation is supported — pass different tier identifiers and initializer sets for builds that ship different binding configurations (e.g., free vs paid plugin tiers).

Boot order
----------

[](#boot-order)

Container must boot before Config and Registry, because the latter two resolve through `InstanceProvider`. The suite Initializer encodes this; piecemeal users must honor it manually.

Runtime overrides
-----------------

[](#runtime-overrides)

The compiled container is not immutable. PHP-DI's `set()` against a built container takes precedence over compiled bindings, so tier switches, test bindings, and third-party extensions keep working at runtime. Compiled containers reject Definition objects via `set()` at runtime — the adapter's `bind()` and `bindFactory()` handle this transparently (eager-resolving raw values when the underlying container is compiled).

Multi-abstract bind semantics
-----------------------------

[](#multi-abstract-bind-semantics)

This integration mirrors PHPNomad's simple `Container::bind()` semantics exactly: when you bind one concrete to multiple abstracts in a single call, all abstracts share the resulting instance. Each abstract aliases to the concrete independently — a later `bind()` that re-points one abstract leaves the others pointing at the original concrete. Self-binding (`bind(Foo::class, Foo::class)`) is special-cased to autowire directly rather than alias to itself.

Requirements
------------

[](#requirements)

- PHP 8.2+
- PHPNomad 2.x or 3.x
- `php-di/php-di` ^7.0

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance93

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

Unknown

Total

1

Last Release

35d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e6206223bd6f2a57b8ac80605b1b5c3521faaec18ad3f20f25fb728a9a13784?d=identicon)[tstandiford](/maintainers/tstandiford)

---

Top Contributors

[![alexstandiford](https://avatars.githubusercontent.com/u/8210827?v=4)](https://github.com/alexstandiford "alexstandiford (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpnomad-php-di-integration/health.svg)

```
[![Health](https://phpackages.com/badges/phpnomad-php-di-integration/health.svg)](https://phpackages.com/packages/phpnomad-php-di-integration)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[phlak/directory-lister

PHP directory lister

2.5k1.4k](/packages/phlak-directory-lister)[infinum/eightshift-libs

WordPress libs developed by Eightshift team to use in modern WordPress.

63123.8k3](/packages/infinum-eightshift-libs)[drupal-code-builder/drupal-code-builder

Code generator for Drupal

27249.5k1](/packages/drupal-code-builder-drupal-code-builder)

PHPackages © 2026

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