Download the PHP package hexmakina/le-marchand without Composer
On this page you can find all versions of the php package hexmakina/le-marchand. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package le-marchand
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
- PSR-11 Compliant: Implements the standard container interface, providing
has
andget
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
Usage
Instantiate and Load Configuration
You can initialize the container with a configuration array:
Access Configuration
Settings are stored under the settings
key:
Register Additional Services
You can register additional services manually:
Core Components
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
andhas
).
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
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:
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:
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
Dynamic Dependency Resolution with Solver
LeMarchand supports complex resolution scenarios using the Solver
:
Singleton Management with Factory
The Factory
simplifies singleton management:
Contributing
Feel free to submit issues or pull requests. Contributions are welcome!
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.