PHPackages                             toolkit/di - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. toolkit/di

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

toolkit/di
==========

some di tool library of the php

v1.0.4(7y ago)56MITPHPPHP &gt;7.1.0

Since Mar 5Pushed 6y ago1 watchersCompare

[ Source](https://github.com/php-toolkit/di)[ Packagist](https://packagist.org/packages/toolkit/di)[ Docs](https://github.com/php-toolkit/di)[ RSS](/packages/toolkit-di/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (2)Versions (6)Used By (0)

Dependency injection container
==============================

[](#dependency-injection-container)

简单的容器管理实现

Install
-------

[](#install)

```
composer require toolkit/di
```

注册服务
----

[](#注册服务)

```
public function set(string $id, mixed $definition, array $opts = []): Container
```

### 参数说明

[](#参数说明)

#### 服务ID名

[](#服务id名)

string `$id` 服务组件注册id

#### 服务定义

[](#服务定义)

mixed(string|array|object|callback) `$definition` 服务实例对象|服务信息定义

- string:

```
   $definition = className
```

- array:

```
   $definition = [
      // 1. 仅类名 参数($definition[0])则传入对应构造方法
      'class' => 'className',
      // 2. 类的静态方法,  参数($definition[0])则传入对应方法 className::staticMethod(args...)
      'class' => 'className::staticMethod',
      // 3. 类的动态方法,  参数($definition[0]) 则传入对应方法 (new className)->method(args...)
      'class' => 'className->method',

      // 设置参数方式, 没有key
      [
          arg1,arg2,arg3,...
      ]

      // 设置属性 ， // prop1 prop2 prop3 将会被收集 作为属性
      prop1 => value1,
      prop2 => value2,
      ... ...

      // 一些服务设置(别名,是否共享). 将会合并到最后一个参数中
      '_options' => [...]
   ]
```

- object:

```
   $definition = new xxClass();
```

- closure:

```
   $definition = function($di){
        return object;
   };
```

#### 选项

[](#选项)

- array `$opts` 选项

```
  [
   'shared' => (bool), 是否共享,单例
   'locked' => (bool), 是否锁定服务
   'aliases' => (array), 别名
   'init' => (bool), 立即初始化
  ]
```

License
-------

[](#license)

MIT

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~89 days

Total

5

Last Release

2634d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.0.0

v1.0.3PHP &gt;7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d23e1decaf354e8f36a7ad61128865dc78dd63336c2d023d79aa3ff8ba2a05ff?d=identicon)[inhere](/maintainers/inhere)

---

Top Contributors

[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (21 commits)")

---

Tags

containerdependency-managerphplibrarytool

### Embed Badge

![Health badge](/badges/toolkit-di/health.svg)

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

PHPackages © 2026

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