Container
The Container package provides a lightweight dependency injection container for Raxos applications. It resolves classes automatically by reflecting on constructors and method parameters, and supports explicit bindings, singletons, tagged variants, property injection and lazy proxies through PHP attributes. The same container can invoke arbitrary callables while autowiring their missing arguments, and a PSR-11 adapter lets it be handed to libraries that expect the standard ContainerInterface.
Highlights
ContainerBinds, resolves and autowires classes, functions and methods through reflection.PsrContainerAdapterExposes a Raxos container as a standard PSR-11 ContainerInterface.SingletonMarks a class so its first autowired instance is cached and reused.TagScopes a binding or a parameter to a named or enum backed variant.InjectInjects a property after construction, optionally behind a lazy proxy.EnvResolves a scalar parameter from an environment variable with type coercion.Explore by category
- Binding and resolving: create a container and register classes, factories, singletons and tagged bindings, then fetch them with
getandhas. - Autowiring and attributes: how constructor and property dependencies are resolved automatically, and the
#[Inject],#[Proxy],#[Tag],#[Singleton]and#[Env]attributes that steer that behavior. - Calling callables: invoke closures, static or instance methods and invokable classes while the container fills in missing arguments.
- Errors and dependency chains: the exception hierarchy raised during resolution, and how
DependencyChainhelps diagnose failures.
Quick example
php
<?php
declare(strict_types=1);
use Raxos\Container\Container;
$container = new Container();
$container->singleton(LoggerInterface::class, FileLogger::class);
$logger = $container->get(LoggerInterface::class);Installation
Install the package with Composer and check the requirements on the installation page.
shell
composer require raxos/container