liquidrazor/diregistry
Composer 安装命令:
composer require liquidrazor/diregistry
包简介
Strict descriptor-driven dependency injection registry library for PHP 8.3+.
关键字:
README 文档
README
DI Registry is a PHP 8.3+ library for descriptor-driven dependency resolution and instantiation.
It is intentionally strict:
- descriptors are explicit data, not executable configuration
- resolution keys are limited to contract or class path
- resolution is deterministic or it fails
- runtime instances are stored outside descriptor metadata
- scalar and configuration values are provided explicitly through a value provider
The library is built from four concrete runtime pieces:
RegistryCompilerturns normalized descriptor definitions into a validatedCompiledRegistryDescriptorResolverselects exactly oneProspectDescriptorDescriptorInstantiatorbuilds an object from that descriptorInMemoryRuntimeInstanceStorehandles singleton, scoped, and pooled runtime behavior
Installation
composer require liquidrazor/diregistry
Requirements:
- PHP 8.3 or newer
- Composer autoloading
- a source of descriptor definitions before runtime
Quick Start
<?php declare(strict_types=1); use LiquidRazor\DIRegistry\Bootstrap\RegistryCompiler; use LiquidRazor\DIRegistry\Contract\DependencyValueProviderInterface; use LiquidRazor\DIRegistry\Descriptor\DependencyDescriptor; use LiquidRazor\DIRegistry\Instantiator\DescriptorInstantiator; use LiquidRazor\DIRegistry\Resolver\DescriptorResolver; use LiquidRazor\DIRegistry\Runtime\InMemoryRuntimeInstanceStore; use LiquidRazor\DIRegistry\Value\RuntimeContext; use LiquidRazor\DIRegistry\Enum\Environment; interface MailerInterface { } final class SmtpMailer implements MailerInterface { public function __construct(public string $dsn) { } } final class NewsletterService { public function __construct(public MailerInterface $mailer) { } } final class ArrayValueProvider implements DependencyValueProviderInterface { public function __construct(private array $values) { } public function canProvide(DependencyDescriptor $dependency, RuntimeContext $context): bool { return array_key_exists($dependency->name, $this->values); } public function provide(DependencyDescriptor $dependency, RuntimeContext $context): mixed { return $this->values[$dependency->name]; } } $definitions = [ [ 'id' => 'service.mailer.smtp', 'classPath' => SmtpMailer::class, 'contracts' => [MailerInterface::class], 'source' => 'config/services.php', 'lifecycle' => 'singleton', 'environments' => ['prod'], 'priority' => 0, 'isDefault' => true, 'constructionStrategy' => 'constructor', 'dependencies' => [ [ 'name' => 'dsn', 'position' => 0, 'kind' => 'scalar', 'target' => 'mailer.dsn', 'required' => true, 'nullable' => false, 'hasDefault' => false, ], ], ], [ 'id' => 'service.newsletter', 'classPath' => NewsletterService::class, 'contracts' => [], 'source' => 'config/services.php', 'lifecycle' => 'transient', 'environments' => ['prod'], 'priority' => 0, 'isDefault' => false, 'constructionStrategy' => 'constructor', 'dependencies' => [ [ 'name' => 'mailer', 'position' => 0, 'kind' => 'contract', 'target' => MailerInterface::class, 'required' => true, 'nullable' => false, 'hasDefault' => false, ], ], ], ]; $registry = (new RegistryCompiler())->compile($definitions, 'build-2026-03-26'); $resolver = DescriptorResolver::forRegistry($registry); $instantiator = DescriptorInstantiator::forRuntime( $resolver, new ArrayValueProvider(['dsn' => 'smtp://localhost']), new InMemoryRuntimeInstanceStore(), ); $context = new RuntimeContext(Environment::Prod); $descriptor = $resolver->resolveClassPath(NewsletterService::class, $context->environment); $service = $instantiator->instantiate($descriptor, $context);
What this example shows:
- the compiler computes descriptor checksums and validates the full descriptor set
- contract dependencies are resolved through the resolver
- scalar dependencies come only from
DependencyValueProviderInterface - singleton reuse is handled by the runtime store, not by registry mutation
Key Constraints
- No alias system.
- No autowiring.
- No fallback from one environment to another.
- No best-effort choice when multiple candidates remain tied.
- No automatic handling of scalar or config dependencies.
- No runtime mutation of compiled registry contents.
Documentation
Start with Documentation Home.
Recommended entry points:
- Overview: design constraints, architecture, and library fit.
- Getting Started: installation, first registry compilation, and first resolution.
- Usage Guide: concrete runtime wiring and operational behavior.
- Reference: public contracts, descriptors, enums, and exceptions.
- Validation & Debug: compile checks, debug validation, and troubleshooting.
Development
composer install vendor/bin/phpunit
liquidrazor/diregistry 适用场景与选型建议
liquidrazor/diregistry 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「di」 「resolver」 「registry」 「dependency-injection」 「instantiator」 「descriptor-driven」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 liquidrazor/diregistry 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 liquidrazor/diregistry 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 liquidrazor/diregistry 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Type transformers, normalizers and resolvers.
resolve openapi keywords
Supporing Symfony's DependencyInjection component for your symfony1 project
Link Registry bundle for Contao Open Source CMS
PhpPlaisio: Company Resolver
PhpPlaisio: Uni Company Resolver
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-26