Skip to content

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

Explore by category

  • Binding and resolving: create a container and register classes, factories, singletons and tagged bindings, then fetch them with get and has.
  • 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 DependencyChain helps 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