定制 hydrakit/php-di 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hydrakit/php-di

Composer 安装命令:

composer require hydrakit/php-di

包简介

PHP-DI container adapter for the Hydra PHP framework

README 文档

README

The one place the framework names a concrete dependency-injection engine.

hydrakit/core defines the ContainerInterface the framework resolves services through — get/has/singleton/instance/bound — but names no DI engine. This package is the default adapter that backs that contract with PHP-DI. An app that prefers another engine writes its own adapter against the same interface, and this package never loads — exactly as hydrakit/nyholm is the swappable PSR-7 adapter.

Usage

The app's composition root builds the container and hands it to the kernel:

use Hydra\PhpDi\Container;

$container = Container::create();          // wraps a fresh PHP-DI container

Kernel::application($container, $environment)
    ->register(new NyholmServiceProvider)
    ->register(new SignerServiceProvider)
    ->register(new HttpServiceProvider(/* ... */))
    ->register(new AppServiceProvider);

Container::create() is the common case, so the composition root needn't name DI\Container itself. To tune PHP-DI (definitions, compilation, proxies), build the underlying container yourself and inject it:

$phpdi = (new \DI\ContainerBuilder())->enableCompilation(__DIR__ . '/cache')->build();
$container = new Container($phpdi);

Binding semantics

PHP-DI caches every resolved entry, so a binding is inherently shared:

  • singleton($abstract, $concrete) — a class-string is autowired; a callable is used as a factory. This is the only binding kind; there is no transient counterpart (per the contract's documented YAGNI stance).
  • instance($abstract, $object) — register an already-constructed object.
  • bound($abstract) — whether the container can resolve the abstract, which for an autowiring engine includes any instantiable class, not only explicitly registered ones. Use it as a capability check, never as evidence a provider ran.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固