Search by

raxos / container

basmilius

A Container for Raxos.

3.2.0 2026-10-02 17:09 UTC

This package is auto-updated.

Last update: 2026-10-03 12:06:19 UTC


README

Bas Milius

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.