raxos / container
A Container for Raxos.
Requires
- php: >=8.5
- jetbrains/phpstorm-attributes: ^1.2
- raxos/contract: *
- raxos/error: *
- raxos/foundation: *
- raxos/reflection: *
Requires (Dev)
- pestphp/pest: ^5.0
- psr/container: ^2.0
Suggests
- psr/container: Required for PsrContainerAdapter to expose the container as a PSR-11 ContainerInterface.
Provides
None
Conflicts
None
Replaces
None
README
Raxos Container
Resolve services through constructor injection, explicit bindings and PHP attributes.
Documentation | Packagist | Raxos
- Class and factory bindings, shared singletons and prebuilt instances.
- Automatic constructor injection and dependency-cycle detection.
- Tagged services and the
#[Inject],#[Singleton],#[Proxy]and#[Tag]attributes. - Dependency injection for callable arguments.
Installation
Requires PHP 8.5 or later. Composer checks the remaining package and extension dependencies declared in composer.json.
composer require "raxos/container:^3.2"
Usage
<?php declare(strict_types=1); use Raxos\Container\Container; require __DIR__ . '/vendor/autoload.php'; final readonly class Catalog { public function name(int $id): string { return "Product {$id}"; } } final readonly class ProductService { public function __construct(public Catalog $catalog) {} } $container = new Container(); $container->singleton(Catalog::class, Catalog::class); $service = $container->get(ProductService::class); echo $service->catalog->name(42);
bind() builds a fresh service on each resolution. singleton() builds once and reuses the instance; instance() registers an object you already have. Constructor dependencies are resolved automatically when no explicit binding exists.
Documentation
Testing
Run this library's Pest suite from the Raxos workspace:
git clone --recurse-submodules https://github.com/basmilius/raxos.git
cd raxos
composer install
vendor/bin/pest --testsuite=container
See Testing Raxos for PHP extensions, integration services and coverage commands. The library's Tests workflow also runs in GitHub Actions.
License
MIT. Copyright (c) 2017 - present Bas Milius.