PHPackages                             zean/sim-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. zean/sim-di

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

zean/sim-di
===========

simple dependency inject container

v1.0(8y ago)211MITPHPPHP &gt;= 7.0.0

Since Jul 25Pushed 8y ago1 watchersCompare

[ Source](https://github.com/JustPoet/SimDI)[ Packagist](https://packagist.org/packages/zean/sim-di)[ RSS](/packages/zean-sim-di/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

SimDI
=====

[](#simdi)

一个简单的PHP依赖注入框架，支持autowire。

附上之前写的一篇文: [用PHP撸一个DI容器](http://www.jianshu.com/p/bcb8cb785ca3)

安装
--

[](#安装)

```
composer require zean/sim-di
```

使用
--

[](#使用)

1. 不使用面向接口编程风格

    假如有Car和Driver两个类，Driver依赖Car

    ```
    class Car
    {
        protected $name = '汽车';

        public function getName()
        {
            return $this->name;
        }
    }
    ```

    ```
    class Driver
    {
        protected $car;

        public function __construct(Car $car)
        {
            $this->car = $car;
        }

        public function drive()
        {
            return '驾驶' . $this->car->getName();
        }
    }
    ```

    当我们需要Diver实例的时候，这时候我们只需要让容器创建，容器会自动注入Car实例

    ```
    $app = \SimDI\Container::getInstance();
    $driver = $app->get(Driver::class);
    echo $driver->drive();
    ```

> output:驾驶汽车

2. 使用面向接口编程风格

假如我们用面向接口的方式来，我稍微修改一下上面的代码：

```
abstract class Car
{
    protected $name = '汽车';

    public function getName()
    {
        return $this->name;
    }
}
```

```
interface Driveable
{
    public function run();
}
```

```
class Benz extends Car implements Driveable
{
    protected $name = '奔驰';

    public function run()
    {
        return $this->getName() . '启动了！';
    }
}
```

```
class Driver
{
    protected $car;

    public function __construct(Driveable $car)
    {
        $this->car = $car;
    }

    public function drive()
    {
        return '驾驶' . $this->car->run();
    }
}
```

面向接口编程时需要有一个配置来指定interface和实现类的对应关系，如下：

```
$config = [
    Driveable::class => Benz::class,
];
```

然后在创建容器的时候我们使用上述配置：

```
$app = \SimDI\Container::getInstance($config);
$driver = $app->get(Driver::class);
echo $driver->drive();
```

> output:驾驶奔驰启动了！

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3216d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f6c9b9cd6a420f29869125178b8dd28cc6ff064e6feb97c5c8de0caa43cf304?d=identicon)[ZhengZean](/maintainers/ZhengZean)

---

Top Contributors

[![JustPoet](https://avatars.githubusercontent.com/u/5744662?v=4)](https://github.com/JustPoet "JustPoet (13 commits)")

---

Tags

dependency-injectionphp7

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

704122.9M10.1k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31278.1M2.0k](/packages/illuminate-container)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)

PHPackages © 2026

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