Download the PHP package kode/di without Composer
On this page you can find all versions of the php package kode/di. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package di
kode/di
高性能 PHP 8.1+ 依赖注入容器,支持属性注入、生命周期管理、协程上下文隔离,兼容 PSR-11。
特性
- PSR-11 兼容 - 实现标准容器接口
- 属性注入 - 基于 PHP 8.1+ Attributes 实现声明式注入
- 生命周期管理 - 单例/原型/懒加载/上下文隔离
- 协程安全 - 支持 Fiber/Swoole/Swow 上下文隔离
- 高性能 - 反射缓存 + 定义缓存
- 零全局状态 - 无全局变量污染
- 框架无关 - 可在任何 PHP 8.1+ 项目中使用
安装
快速开始
基本使用
属性注入
生命周期类型
| 类型 | 方法 | 说明 |
|---|---|---|
| 单例 | singleton() |
全局唯一实例 |
| 原型 | prototype() |
每次获取创建新实例 |
| 懒加载 | lazy() |
延迟实例化 |
| 上下文隔离 | contextual() |
协程/Fiber间隔离 |
上下文隔离
服务提供者
上下文绑定
标签
API 参考
Container
| 方法 | 说明 |
|---|---|
bind(id, concrete, lifecycle) |
绑定服务 |
singleton(id, concrete) |
绑定单例 |
prototype(id, concrete) |
绑定原型 |
lazy(id, concrete) |
绑定懒加载 |
contextual(id, concrete) |
绑定上下文隔离 |
instance(id, instance) |
绑定实例 |
alias(alias, id) |
设置别名 |
extend(id, callback) |
扩展服务 |
get(id) |
获取服务 |
has(id) |
检查服务是否存在 |
make(id, parameters) |
创建实例 |
call(callback, parameters) |
调用方法 |
resolved(id) |
检查是否已解析 |
forget(id) |
移除绑定 |
flush() |
清空容器 |
Attributes
| 属性 | 目标 | 说明 |
|---|---|---|
#[Inject] |
Property, Parameter | 标记注入点 |
#[Autowire] |
Class, Property, Method | 启用自动装配 |
#[Singleton] |
Class | 标记为单例 |
#[Prototype] |
Class | 标记为原型 |
#[Contextual] |
Class | 标记为上下文隔离 |
与其他 kode 组件集成
兼容性
| PHP 版本 | 支持状态 |
|---|---|
| PHP 8.1 | ✅ 完全支持 |
| PHP 8.2 | ✅ 完全支持 |
| PHP 8.3 | ✅ 完全支持 |
| PHP 8.4 | ✅ 完全支持 |
| PHP 8.5 | ✅ 完全支持 |
| 框架 | 兼容性 |
|---|---|
| Laravel | ✅ 完全兼容 |
| Symfony | ✅ 完全兼容 |
| ThinkPHP 8 | ✅ 完全兼容 |
| Webman | ✅ 完全兼容 |
| Hyperf | ✅ 完全兼容 |
| 原生 PHP | ✅ 完全兼容 |
测试
许可证
Apache License 2.0
All versions of di with dependencies
PHP Build Version
Package Version
The package kode/di contains the following files
Loading the files please wait ...