PHPackages                             yuandian/container - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. yuandian/container

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

yuandian/container
==================

PHP Container.

v1.0.2(9mo ago)1181MITPHPPHP &gt;=8.1

Since May 23Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/yuan-dian/container)[ Packagist](https://packagist.org/packages/yuandian/container)[ RSS](/packages/yuandian-container/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (1)

container CI容器
==============

[](#container-ci容器)

安装
==

[](#安装)

`composer require yuandian/container`

使用协程 2选1 【需要加载对应的C扩展】
=====================

[](#使用协程-2选1-需要加载对应的c扩展)

- 使用swow: `composer require swow/swow`
- 使用swoole：`composer require swoole/ide-helper`

特性
==

[](#特性)

- 基于[think-container](https://github.com/top-think/think-container)改造
- 支持长生命周期与协程请求生命周期的管理（协程请求生命周期使用swow|swoole协程实现）
- 支持PSR-11规范
- 支持依赖注入
- 支持通过`#[Inject]`注解实现属性注入
- 支持容器对象绑定
- 支持闭包绑定
- 支持接口绑定

Container
=========

[](#container)

```
// 获取容器实例
$container = \yuandian\Container\Container::getInstance();
// 绑定一个类、闭包、实例、接口实现到容器
$container->bind('cache', '\app\common\Cache');
// 判断是否存在对象实例
$container->has('cache');
// 从容器中获取对象实例
$container->get('cache');
// 从容器中获取对象，没有则自动实例化
$container->make('cache');

// 从容器中获取对象，没有则自动实例化【没有绑定标识】
$container->make(Cache::class);

// 绑定接口到具体实现
$container->bind(LoggerInterface::class, FileLogger::class);

// 执行某个方法或者闭包 支持依赖注入
$container->invoke($callable, $vars);
// 执行某个类的实例化 支持依赖注入
$container->invokeClass($class, $vars);

// 绑定一个类实例到全局容器
$container->instanceGlobal($class, $instance)
// 绑定一个类实例到请求容器
$container->instanceRequest($class, $instance)
```

捐献
--

[](#捐献)

[![](./wechat.png)](./wechat.png)[![](./alipay.png)](./alipay.png)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance72

Regular maintenance activity

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~33 days

Total

3

Last Release

294d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8101f03acc9ab7ed572b6b5c7a8b7ac3fdfc1d01060bda55bafe9ef0d7ebc5bf?d=identicon)[yuan-dian](/maintainers/yuan-dian)

---

Top Contributors

[![yuan-dian](https://avatars.githubusercontent.com/u/33216505?v=4)](https://github.com/yuan-dian "yuan-dian (24 commits)")

---

Tags

phpcontainerci

### Embed Badge

![Health badge](/badges/yuandian-container/health.svg)

```
[![Health](https://phpackages.com/badges/yuandian-container/health.svg)](https://phpackages.com/packages/yuandian-container)
```

###  Alternatives

[lctrs/psalm-psr-container-plugin

Let Psalm understand better psr11 containers

17648.1k13](/packages/lctrs-psalm-psr-container-plugin)[gacela-project/container

A minimalistic container dependency resolver

1175.2k2](/packages/gacela-project-container)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
