phpsoftbox/container

Dependency injection container for the PhpSoftBox framework

Maintainers

Package info

github.com/phpsoftbox/container

pkg:composer/phpsoftbox/container

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2026-06-03 13:51 UTC

This package is auto-updated.

Last update: 2026-06-03 13:54:53 UTC


README

About

phpsoftbox/container — DI-контейнер для PhpSoftBox с PSR-11 API и дополнительными runtime-операциями.

Ключевые возможности:

  • get() / has() (PSR-11)
  • runtime set() определений
  • make() для не-shared резолва entry
  • call() для вызова callable с DI параметров
  • autowiring по type-hint
  • decorators (decorate)
  • native lazy-прокси на PHP 8.5 (ReflectionClass::newLazyProxy)
  • build-time валидация lazy-конфигурации
  • compilation metadata cache (enableCompilation())
  • warmup (warmup())

Требования

  • PHP ^8.4 (фактически lazy использует API PHP 8.5 Reflection)
  • psr/container:^2.0

Quick Start

<?php

use PhpSoftBox\Container\ContainerBuilder;
use Psr\Container\ContainerInterface;
use function PhpSoftBox\Container\autowire;
use function PhpSoftBox\Container\factory;
use function PhpSoftBox\Container\get;

$builder = new ContainerBuilder();
$builder->useAutowiring(true);
$builder->addDefinitions([
    LoggerInterface::class => autowire(Logger::class),
    UserService::class => factory(
        static fn (ContainerInterface $c): UserService => new UserService($c->get(LoggerInterface::class)),
    ),
    UserServiceInterface::class => get(UserService::class),
]);
$builder->lazy(UserService::class);

$container = $builder->build();

Production

$builder->enableCompilation(__DIR__ . '/var/cache/di');
$container = $builder->build();

enableCompilation() записывает container.compiled.php с fingerprint конфигурации и lazy metadata.

Для CI/deploy можно прогреть контейнер:

$container = $builder->warmup();

warmup([], false) прогревает wiring без инициализации lazy-объектов.

Оглавление