Download the PHP package mykemeynell/reflection without Composer
On this page you can find all versions of the php package mykemeynell/reflection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mykemeynell/reflection
More information about mykemeynell/reflection
Files in mykemeynell/reflection
Package reflection
Short Description Tiny PHP reflection implementation
License MIT
Informations about the package reflection
Reflection
Reflection is a dependency injection container for PHP powered by auto-wiring and reflection.
It supports auto-wiring, contextual bindings, singletons, attribute-driven resolution, runtime parameter overrides, circular dependency detection, and PSR-11 compliance.
Features
- Auto-Wiring: Resolves class constructor dependencies automatically using reflection.
- PSR-11 Compliance: Implements
Psr\Container\ContainerInterface(getandhas). - Contextual Binding: Configure different implementations for specific classes using
when()->needs()->give(). - Singletons: Share instances across multiple resolutions.
- Resolution Attributes: Declare injection targets, scalar values, and singleton lifecycles directly on classes.
- Parameter Overrides: Pass runtime parameters as associative arrays or named arguments.
- Circular Dependency Detection: Detects recursive dependency chains and throws descriptive exceptions.
- Helper Function: Global
app()helper for quick access and resolution.
Requirements
- PHP 8.3 or higher
psr/container ^2.0
Installation
Quick Start
Usage
Auto-Wiring
Classes with type-hinted constructor dependencies resolve without manual configuration:
Default parameter values are used when no argument is supplied:
Bindings
Interface to Implementation
Closure Factory
Singletons & Shared Instances
Register a singleton to return the same instance on later resolutions:
Register an existing instance:
Contextual Bindings
Inject different implementations based on the consumer class:
give() also accepts a closure or a concrete instance:
Parameter Overrides
Override constructor parameters using named arguments:
Associative parameter arrays remain supported:
The previous named parameter-array form remains supported for compatibility:
Named arguments can also be used through the container returned by app():
Resolution Attributes
Use Inject when a constructor parameter needs a specific resolution target:
An ordinary Inject is a fallback after contextual and global bindings. Add Override when the injection point must take precedence over those registrations:
Runtime arguments always take precedence, including when Override is present.
Use Value for scalar constructor configuration:
Value attributes are checked against the declared parameter type. A runtime argument overrides the attribute value.
Use Singleton to share an automatically resolved concrete class:
An explicit instance(), singleton(), or transient bind() registration overrides the class attribute.
Resolution Precedence
Object dependencies use this order:
- Runtime argument
- Contextual binding
- Registered instance or global binding
Inject- Automatic concrete-class resolution
- Constructor default
For parameters marked with both Inject and Override, Inject moves directly below the runtime argument. Scalar parameters use runtime argument, Value, then constructor default. Lifecycle selection uses registered instance, explicit singleton, explicit transient binding, Singleton, then transient automatic resolution.
Circular Dependency Detection
Circular dependencies are detected automatically during resolution:
PSR-11 Compliance
Reflection implements Psr\Container\ContainerInterface:
PSR-11 exception classes:
mykemeynell\Reflection\Exceptions\NotFoundException(implementsPsr\Container\NotFoundExceptionInterface)mykemeynell\Reflection\Exceptions\ContainerException(implementsPsr\Container\ContainerExceptionInterface)mykemeynell\Reflection\Exceptions\DependencyNotSpecifiedException(implementsPsr\Container\ContainerExceptionInterface)
Helper Function
Import the app helper function:
Testing
Run tests:
Check code style:
Format code style:
Install the PHP 8.4 static-analysis toolchain and run PHPStan:
License
MIT License. See LICENSE for details.