Download the PHP package denosyscore/container without Composer
On this page you can find all versions of the php package denosyscore/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download denosyscore/container
More information about denosyscore/container
Files in denosyscore/container
Package container
Short Description PSR-11 compliant dependency injection container with autowiring, contextual bindings, and service decorators for PHP 8.2+
License MIT
Informations about the package container
denosyscore/container
A PSR-11 compliant dependency injection container for PHP 8.2+. Supports autowiring, contextual bindings, tagged services, lazy proxies, scoped lifetimes, method injection, decorators, and built-in testing and profiling utilities.
Requirements
- PHP ^8.2
Installation
Quick Start
Autowiring
The container inspects constructor type-hints and resolves dependencies automatically. No explicit registration is needed for concrete classes:
Union-typed parameters are tried in order. Nullable and defaulted parameters fall back gracefully without throwing.
Explicit Bindings
bind()
Register an abstract (interface or string key) to a concrete implementation or factory closure:
singleton()
Resolved once; the same instance is returned on every subsequent call:
instance()
Register a pre-built object as a shared instance:
alias()
Create a short name for a bound abstract. The abstract must already be bound or be an instantiable class:
extend()
Wrap an existing binding or resolved instance with additional behavior:
Contextual Bindings
Inject different implementations of the same interface depending on which class is requesting it:
Supply all services tagged with a given tag to a context:
Tagged Services
Group related bindings under a shared tag and resolve all of them at once:
A single abstract can carry multiple tags:
Scoped Bindings
Override bindings within a bounded scope. The original bindings are automatically restored when the callable returns:
Lazy Loading
Defer resolution until the first method call. Useful for expensive services that may not be needed on every request path:
The proxy implements Denosys\Container\LazyProxy and transparently forwards all method calls to the underlying instance once triggered.
Method Injection
call()
Invoke any callable with automatic injection of type-hinted parameters:
callStatic()
Call a static method with automatic injection:
Decorators
decorate()
Wrap a resolved service. Multiple decorators are applied in descending $priority order (higher runs first):
middleware()
Middleware behaves like a decorator without priority ordering. Applied in registration order, after all decorate() layers:
Testing Utilities
mock()
Replace a binding with a test double. Mocks take priority over all other bindings and are never decorated:
spy()
Wrap a real service instance to track its resolution count and timing without replacing it:
Container Validation
Check for misconfigured or unresolvable bindings without instantiating anything:
ValidationIssue severity levels: error, warning, info.
Performance
getPerformanceMetrics()
Returns a PerformanceReport with timing, cache ratios, and memory stats accumulated since the container was constructed:
getResolutionHistory()
Returns a ring-buffer of recent resolution records (default limit: 1000 entries):
Lower the ring-buffer size to reduce memory overhead:
License
MIT
All versions of container with dependencies
psr/container Version ^2.0
denosyscore/contracts Version ^0.2
denosyscore/events Version ^0.2