phpsoftbox / container
Dependency injection container for the PhpSoftBox framework
dev-master
2026-06-03 13:51 UTC
Requires
- php: ^8.4
- psr/container: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.93
- phpsoftbox/cli-app: dev-master
- phpsoftbox/cs-fixer: ^1.1.0
- phpunit/phpunit: ^11.2
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 резолва entrycall()для вызова 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-объектов.