PHPackages                             graychen/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. graychen/container

ActiveLibrary

graychen/container
==================

a container for interface and container

v1.0.0(8y ago)119MITPHP

Since Feb 22Pushed 8y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (3)Used By (0)

一个容器为了接口和实体类的解耦
===============

[](#一个容器为了接口和实体类的解耦)

[![StyleCI](https://camo.githubusercontent.com/e50c6bec1908814da7e15cb33837fa6ec48dfbc11c5d1a8466fe37d0a967f77a/68747470733a2f2f7374796c6563692e696f2f7265706f732f36343430383735372f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/64408757)[![Build Status](https://camo.githubusercontent.com/ecf8204d60ed63f87e45729e5b690ceb59badd6e5b299c2e12c4f3c415800103/68747470733a2f2f7472617669732d63692e6f72672f477261796368656e2f436f6e7461696e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Graychen/Container)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f0ed25e1aa1416cade23fa64a23b5a5ea4d3f88c9a2824c21e10ca7ba1a8fce0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f477261796368656e2f436f6e7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Graychen/Container/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/50cfa15006ba25b81c7e674d136543792ace69ff893e1c2b0def0243e326f3c6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f477261796368656e2f436f6e7461696e65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Graychen/Container/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/50cfa15006ba25b81c7e674d136543792ace69ff893e1c2b0def0243e326f3c6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f477261796368656e2f436f6e7461696e65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Graychen/Container/?branch=master)

如何导入
----

[](#如何导入)

```
composer require graychen/container
```

如何使用
----

[](#如何使用)

首先我们在文件中引入我们的容器

```
 use graychen\container\Container;

```

然后我们再将类注册到容器中，用字符串进行映射

#### 匿名函数方式注册

[](#匿名函数方式注册)

```
$container = new Container();
$container->setShared("logShared", function ($content="") {
    return new Log($content);
});
$log=$container->get("logShared", array("writeContent"));

```

#### 类名方式注册

[](#类名方式注册)

```
$container = new Container();
$container->set("log", "graychen\container\\tests\Fixtures\Log");
$log=$container->get("log", array("setString"));

```

#### 直接传入实例化的对象的注册

[](#直接传入实例化的对象的注册)

```
 $container = new Container();
 $container->offsetSet("log", new Log());
 $container->offsetGet("log")

```

### 容器中的判断语句

[](#容器中的判断语句)

#### 判断容器中是否存在这个类

[](#判断容器中是否存在这个类)

```
$container->offsetExists("log")

```

#### 去除容器中的示例

[](#去除容器中的示例)

```
$container->offsetUnset("write")

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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

Unknown

Total

1

Last Release

2998d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4189971?v=4)[Graychen](/maintainers/Graychen)[@Graychen](https://github.com/Graychen)

---

Top Contributors

[![Graychen](https://avatars.githubusercontent.com/u/4189971?v=4)](https://github.com/Graychen "Graychen (15 commits)")

---

Tags

composer-package

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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