PHPackages                             hexmakina/le-marchand - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. hexmakina/le-marchand

ActivePackage[PSR &amp; Standards](/categories/psr-standards)

hexmakina/le-marchand
=====================

LeMarchand is a PSR-11 container, locator and dependency injector

0.2.0(3y ago)1219[2 issues](https://github.com/HexMakina/LeMarchand/issues)1mitPHPPHP &gt;=7.1

Since Aug 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/HexMakina/LeMarchand)[ Packagist](https://packagist.org/packages/hexmakina/le-marchand)[ RSS](/packages/hexmakina-le-marchand/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (1)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d9faee927405bb7e2dd59eeb34dc3b4e618a2ac0cd2a900a699985f7a2d6f469/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4865784d616b696e612f4c654d61726368616e642f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/HexMakina/LeMarchand/?branch=main)[![PSR-4 Compliant](https://camo.githubusercontent.com/2f4700086d2e2fe807bd70b7479ef20330e582cd6a594f203de5b49015d15ab8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d342d627269676874677265656e)](https://camo.githubusercontent.com/2f4700086d2e2fe807bd70b7479ef20330e582cd6a594f203de5b49015d15ab8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d342d627269676874677265656e)[![PSR-11 Compliant](https://camo.githubusercontent.com/5824ddb8420a429e217048b30a43963eb7f038270a9a10c918302998f1e5aa2f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d31312d627269676874677265656e)](https://camo.githubusercontent.com/5824ddb8420a429e217048b30a43963eb7f038270a9a10c918302998f1e5aa2f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d31312d627269676874677265656e)[![PSR-12 Compliant](https://camo.githubusercontent.com/f5517c4a8a2438b2152b62762e852385c588ff2c1d8a028ba56d0626e1151e94/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d31322d627269676874677265656e)](https://camo.githubusercontent.com/f5517c4a8a2438b2152b62762e852385c588ff2c1d8a028ba56d0626e1151e94/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d31322d627269676874677265656e)[![PHP 7.0 Required](https://camo.githubusercontent.com/c3f404881a59cc0a4fcbd46c5f4f02cac8f01f589fc818f74538a88353f854fb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302d627269676874677265656e)](https://camo.githubusercontent.com/c3f404881a59cc0a4fcbd46c5f4f02cac8f01f589fc818f74538a88353f854fb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302d627269676874677265656e)

**LeMarchand**
==============

[](#lemarchand)

A **PSR-11 compliant service container** built for the kadro framework. It combines features of a **Service Locator** and **Dependency Injection Container**, designed to manage configurations, services, and dependencies efficiently. LeMarchand is complemented by two core components:

- **Solver**: Handles dynamic dependency resolution.
- **Factory**: Manages object instantiation and caching.

---

**Features**
------------

[](#features)

- **PSR-11 Compliant**: Implements the standard container interface, providing `has` and `get` methods.
- **Dynamic Dependency Resolution**: Supports complex resolution strategies via the `Solver`.
- **Efficient Instance Management**: Includes a `Factory` to cache instances and manage singletons.
- **Flexible Configuration**: Easily load settings, register services, and resolve dependencies.
- **Extensible**: Designed for use in applications that require advanced dependency management.

---

**Installation**
----------------

[](#installation)

```
composer require hexmakina/le-marchand
```

---

**Usage**
---------

[](#usage)

### **Instantiate and Load Configuration**

[](#instantiate-and-load-configuration)

You can initialize the container with a configuration array:

```
$settings = [
  'app' => [
    'name' => 'KORAL',
    'production_host' => 'engine.hexmakina.be',
    'session_start_options' => ['session_name' => 'koral-alias'],
    'time_window_start' => '-3 months',
    'time_window_stop' => '+1 month',
  ],
  'controller_namespaces' => [
    'App\\Controllers\\',
    'HexMakina\\koral\\Controllers\\',
    'HexMakina\\kadro\\Controllers\\'
  ]
];

$box = new LeMarchand($settings);
```

### **Access Configuration**

[](#access-configuration)

Settings are stored under the `settings` key:

```
$box->has('settings'); // returns true
$box->has('settings.app.name'); // returns true
$box->get('settings.app.name'); // returns 'KORAL'
```

### **Register Additional Services**

[](#register-additional-services)

You can register additional services manually:

```
$box->register('HexMakina\Crudites\ConnectionInterface', $connection);
```

---

**Core Components**
-------------------

[](#core-components)

### **1. LeMarchand**

[](#1-lemarchand)

LeMarchand is the main container class. It:

- Implements the PSR-11 `ContainerInterface`.
- Manages a centralized collection of services and configurations.
- Provides mechanisms for retrieving and checking for services (`get` and `has`).

#### Key Features:

[](#key-features)

- Singleton Pattern: Ensures only one instance of the container exists.
- Configuration Management: Supports hierarchical settings (e.g., `settings.database.host`).
- Integration with Solver and Factory for advanced dependency resolution and instantiation.

---

### **2. Solver**

[](#2-solver)

The `Solver` class extends LeMarchand’s capabilities by dynamically resolving dependencies using multiple strategies:

- **Settings Probe**: Resolves hierarchical keys (e.g., `settings.app.name`) from the configuration array.
- **Class Probe**: Instantiates a class if it exists.
- **Interface Probe**: Maps interfaces to implementations via a wiring configuration.
- **Cascade Probe**: Dynamically resolves classes using a namespace cascade for patterns like MVC.

#### Example:

[](#example)

```
// Resolve a setting
$solver->probeSettings('settings.app.name'); // Returns 'KORAL'

// Resolve a class
$solver->probeClasses(App\Controllers\UserController::class);

// Resolve an interface
$solver->probeInterface(App\Contracts\LoggerInterface::class);

// Resolve dynamically using namespaces
$solver->probeCascade('Controllers\UserController');
```

---

### **3. Factory**

[](#3-factory)

The `Factory` class handles the creation and caching of class instances. It:

- Dynamically resolves constructor dependencies using the container.
- Caches instances to prevent redundant object creation.
- Handles singleton creation for classes with private constructors.

#### Example:

[](#example-1)

```
$factory = new Factory($box);

// Retrieve a cached instance or create a new one
$instance = $factory->serve(App\Services\EmailService::class);

// Build a new instance of a class
$newInstance = $factory->build(App\Models\User::class);

// Create a singleton
$singleton = $factory->buildSingleton(new \ReflectionClass(App\Services\Singleton::class), ['getInstance', []]);
```

---

**Error Handling**
------------------

[](#error-handling)

LeMarchand adheres to PSR-11 standards for error handling:

- **`Psr\Container\NotFoundExceptionInterface`**: Thrown when a service or configuration is not found.
- **`Psr\Container\ContainerExceptionInterface`**: Thrown when there’s an issue resolving a service.

---

**Advanced Usage**
------------------

[](#advanced-usage)

### Dynamic Dependency Resolution with Solver

[](#dynamic-dependency-resolution-with-solver)

LeMarchand supports complex resolution scenarios using the `Solver`:

```
// Resolve a service with constructor dependencies
$controller = $box->get(App\Controllers\UserController::class);
```

### Singleton Management with Factory

[](#singleton-management-with-factory)

The `Factory` simplifies singleton management:

```
$singleton = $factory->buildSingleton(
    new \ReflectionClass(App\Services\Logger::class),
    ['getInstance', []]
);
```

---

**Contributing**
----------------

[](#contributing)

Feel free to submit issues or pull requests. Contributions are welcome!

---

**Lore &amp; Homage**
---------------------

[](#lore--homage)

The **LeMarchand** box, also known as the **Lament Configuration**, was introduced in *The Hellbound Heart* novella and later appeared in the *Hellraiser* film series. This project pays homage to its mystique by solving the "lamentations" of dependency management.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

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

Recently: every ~85 days

Total

12

Last Release

1356d ago

PHP version history (3 changes)0.0.1PHP &gt;=7.4

0.0.3PHP &gt;=7.0

0.1.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/973280baa800481e705055e3603932b782065471f88e7a3bedd350c3b3a8bcfd?d=identicon)[HexMakina](/maintainers/HexMakina)

---

Top Contributors

[![HexMakina](https://avatars.githubusercontent.com/u/20891495?v=4)](https://github.com/HexMakina "HexMakina (52 commits)")

---

Tags

phpphp7psr-11psr-12containerPSR-11psr11

### Embed Badge

![Health badge](/badges/hexmakina-le-marchand/health.svg)

```
[![Health](https://phpackages.com/badges/hexmakina-le-marchand/health.svg)](https://phpackages.com/packages/hexmakina-le-marchand)
```

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[phpwatch/simple-container

A fast and minimal PSR-11 compatible Dependency Injection Container with array-syntax and without auto-wiring

1810.1k2](/packages/phpwatch-simple-container)

PHPackages © 2026

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