Download the PHP package lighthouse/container without Composer
On this page you can find all versions of the php package lighthouse/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lighthouse/container
More information about lighthouse/container
Files in lighthouse/container
Package container
Short Description PSR-11 Dependency Injection Container for the Lighthouse framework
License MIT
Informations about the package container
Lighthouse Container
A PSR-11 compliant Dependency Injection Container for the Lighthouse framework.
Installation
Requirements
- PHP 8.2 or higher
Features
- Full PSR-11 compliance
- Autowiring via reflection
- Manual bindings
- Singletons
- Factories
- Interface to implementation binding
- Method injection
- Circular dependency detection
Quick Start
Basic Autowiring
The container can automatically resolve class dependencies:
Manual Bindings
Bind interfaces to implementations:
Closure Bindings
Use closures for complex instantiation:
Singletons
Register a binding that returns the same instance:
Register Existing Instance
Factories
Register a factory that creates a new instance each time:
Method Injection
Call methods with automatic dependency resolution:
PSR-11 Methods
Error Handling
The container throws PSR-11 compliant exceptions:
Circular Dependency Detection
The container detects circular dependencies and throws a clear error:
API Reference
| Method | Description |
|---|---|
get(string $id) |
Resolve an entry (PSR-11) |
has(string $id) |
Check if entry exists (PSR-11) |
bind(string $id, mixed $concrete) |
Register a binding |
singleton(string $id, mixed $concrete) |
Register a shared binding |
instance(string $id, mixed $instance) |
Register an existing instance |
factory(string $id, callable $factory) |
Register a factory |
call(object\|string $target, string $method, array $params) |
Call method with DI |
flush() |
Clear all bindings and instances |
getBindings() |
Get all registered binding IDs |
isShared(string $id) |
Check if binding is a singleton |
Testing
License
MIT License. See LICENSE for details.
Part of the Lighthouse Framework
This package is part of the Lighthouse Framework, an educational PHP framework designed to teach how modern frameworks work internally.