PHPackages                             twinkle/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. twinkle/di

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

twinkle/di
==========

实现PSR-11容器接口

v1.0.3(6y ago)436221MITPHPPHP &gt;=5.6.0

Since Jan 14Pushed 6y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (2)Used By (1)

Twinkle\\DI
===========

[](#twinkledi)

实现PSR-11容器接口

[![Build Status](https://camo.githubusercontent.com/ca8ff7d30bfe8aa8e671e01f4922e789c88d54360c6dfd21484dea84df3676a8/68747470733a2f2f7472617669732d63692e6f72672f6163746f72733331352f44492e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/actors315/DI)

安装
--

[](#安装)

```
composer require twinkle/di --prefer-dist --optimize-autoloader

```

示例
--

[](#示例)

Container

```
$definitions = [
    'hello' => [
        'class' => \HelloWorld::class,
    ]
];
$container = new \Twinkle\DI\Container($definitions);

// 是否注入容器
isset($container['hello'])

// 获取实例
$instance = $container['hello'];
$instance->someMethod();

// 释放
unset($container['hello']);

```

ServiceLocator

```
namespace App\Services;
class HelloService
{

    public function sayHello()
    {
        return 'hello';
    }
}

namespace App\Controllers;
use App\Services\HelloService;
use Twinkle\DI\ServiceLocatorTrait;

/**
 * Class HelloController
 * @package App\Controllers
 * @property HelloService $helloService
 */
class HelloController
{

    use ServiceLocatorTrait;

    public static function supportAutoNamespaces()
    {
        return [
            'App\\Services',
            'Twinkle\\Services'
        ];
    }

    public function indexAction()
    {
        echo $this->helloService->sayHello();
    }

}

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

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

2311d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/901366a9dd8b8c4dbc9541cba4154174e50c98fea38964e96443980d5465b75c?d=identicon)[actors315](/maintainers/actors315)

---

Top Contributors

[![actors315](https://avatars.githubusercontent.com/u/3014232?v=4)](https://github.com/actors315 "actors315 (12 commits)")

---

Tags

containerdipsr-11

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[league/container

A fast and intuitive dependency injection container.

86387.8M343](/packages/league-container)[lctrs/psalm-psr-container-plugin

Let Psalm understand better psr11 containers

17648.1k13](/packages/lctrs-psalm-psr-container-plugin)[phpwatch/simple-container

A fast and minimal PSR-11 compatible Dependency Injection Container with array-syntax and without auto-wiring

1810.1k2](/packages/phpwatch-simple-container)

PHPackages © 2026

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