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

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

godruoyi/easy-container
=======================

A small PHP 5.3 dependency injection container extended from Laravel container.

3.0.0(2y ago)335.0k43MITPHPPHP &gt;=8.1

Since Oct 12Pushed 2y ago2 watchersCompare

[ Source](https://github.com/godruoyi/easy-container)[ Packagist](https://packagist.org/packages/godruoyi/easy-container)[ Docs](https://github.com/godruoyi/easy-container)[ RSS](/packages/godruoyi-easy-container/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (9)Used By (3)

A simple dependency injecting container from laravel.
=====================================================

[](#a-simple-dependency-injecting-container-from-laravel)

 [![styleci passed](https://github.com/godruoyi/easy-container/actions/workflows/php.yml/badge.svg?branch=master)](https://github.com/godruoyi/easy-container) [ ![easy-container](https://camo.githubusercontent.com/3d0da22ca3648d16ba7a816325996a883f2838f572af267b8be4176324b803d6/68747470733a2f2f636f6465636f762e696f2f67682f676f6472756f79692f656173792d636f6e7461696e65722f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d4852586745507338716c) ](https://codecov.io/gh/godruoyi/easy-container) [![Latest Stable Version](https://camo.githubusercontent.com/2b43109ddd9ae7ad46d37c34b81363fb7647254561e10bf5159b6d10ff06184f/68747470733a2f2f706f7365722e707567782e6f72672f676f6472756f79692f656173792d636f6e7461696e65722f762f737461626c652e737667)](https://packagist.org/packages/godruoyi/easy-container) [![Total Downloads](https://camo.githubusercontent.com/be1b22ff62f182b53329489c062803de48fc73c411b1930508a8c3d21623b1f7/68747470733a2f2f706f7365722e707567782e6f72672f676f6472756f79692f656173792d636f6e7461696e65722f646f776e6c6f616473)](https://packagist.org/packages/godruoyi/easy-container) [![License](https://camo.githubusercontent.com/2d2f1261f9f38789d94afd9eb82ad2a935aa4be0553a3ac96c5d39d00fcabdc5/68747470733a2f2f706f7365722e707567782e6f72672f676f6472756f79692f656173792d636f6e7461696e65722f6c6963656e7365)](https://packagist.org/packages/godruoyi/easy-container)

Why
===

[](#why)

Currently more popular `php` container:

- [Pimple](https://pimple.symfony.com/)
- [Laravel Container](https://github.com/illuminate/container)
- [Other Dependency-injection Container](https://github.com/ziadoz/awesome-php#dependency-injection)

`Pimple` is a simple and excellent `php 5.3` container, which is also the most used service container, and the installed capacity of [packagist](https://packagist.org/packages/pimple/pimple) is also up to `1000W+` .But `Pimple` just a simple service container that does not support many features such as:

```
class Cache
{
    public function __construct(Config $config){}
}

class Config
{
}

// not support
$cache = $container->make('Cache');
```

> Pimple Does not support the automatic injection of dependency parameters, when you need to rely on other objects object, you can only instantiate the required parameters.

`Laravel Container` is the most full-featured service container, including auto-injection, load-loading, alias, TAG, and so so. But the official does not recommend using the component in non-laravel project.

> If you have noticed the `composer.json` file under that component，You will find that he depends on the [illuminate/contracts](https://github.com/illuminate/contracts) component.([see also](https://github.com/laravel/framework/issues/21435))

Based on this, [easy-container](https://github.com/godruoyi/easy-container) was born, and the project code relied heavily on [Laravel Container](https://github.com/illuminate/container) 😄 😄 . You can use it like a `Laravel Container` container.

Install
=======

[](#install)

SDK VersionPHP VersionComposer Command3.x&gt;= 8.1`composer require "easy-container:^3.0"`2.x&gt;= 7.2`composer require "easy-container:^2.1"`1.x&gt;= 5.6`composer require "easy-container:^2.1"`Use
===

[](#use)

You can get more help with [container usage](https://laravel.com/docs/5.5/container) at [laravel.com](https://laravel.com).

Initialize the container.

```
$app = new Godruoyi\Container\Container;
```

> The following documents support from [laravel.com](https://laravel.com/docs/5.5/container), reproduced please indicate the source.

#### Simple Bindings

[](#simple-bindings)

We can register a binding using the `bind` method, passing the class or interface name that we wish to register along with a `Closure` that returns an instance of the class:

```
$app->bind('HelpSpot\API', function ($app) {
    return new HelpSpot\API($app->make('HttpClient'));
});
```

> Note,All anonymous functions accept the service container instance as a parameter.

#### Binding A Singleton

[](#binding-a-singleton)

The `singleton` method binds a class or interface into the container that should only be resolved one time. Once a singleton binding is resolved, the same object instance will be returned on subsequent calls into the container:

```
$app->singleton('HelpSpot\API', function ($app) {
    return new HelpSpot\API($app->make('HttpClient'));
});
```

> Each time you call `$app['HelpSpot\API']` will return the same object.

#### Binding A Singleton

[](#binding-a-singleton-1)

The `singleton` method binds a class or interface into the container that should only be resolved one time. Once a singleton binding is resolved, the same object instance will be returned on subsequent calls into the container:

```
$api = new HelpSpot\API(new HttpClient);

$app->instance('HelpSpot\API', $api);

```

### Binding Interfaces To Implementations

[](#binding-interfaces-to-implementations)

A very powerful feature of the service container is its ability to bind an interface to a given implementation. For example, let's assume we have an `EventPusher` interface and a `RedisEventPusher` implementation. Once we have coded our `RedisEventPusher` implementation of this interface, we can register it with the service container like so:

```
$app->bind(
    'App\Contracts\EventPusher',
    'App\Services\RedisEventPusher'
);

```

This statement tells the container that it should inject the `RedisEventPusher` when a class needs an implementation of `EventPusher`. Now we can type-hint the `EventPusher` interface in a constructor, or any other location where dependencies are injected by the service container:

```
use App\Contracts\EventPusher;

/**
 * Create a new instance of the class, which will be injected into the App\Services\RedisEventPusher instance.
 *
 * @param  EventPusher  $pusher
 * @return void
 */
public function __construct(EventPusher $pusher)
{
    $this->pusher = $pusher;
}

```

Resolving
---------

[](#resolving)

#### The `make` Method

[](#the-make-method)

You may use the `make` method to resolve a class instance out of the container(regardless of what type of parameter the object needs). The `make` method accepts the name of the class or interface you wish to resolve:

```
$api = $app->make('HelpSpot\API');

```

The `mark` method is the most important method I think of,You can simply use the "type prompt" way to add dependencies,the container will automatically parse all the parameters you need.

```
// Automatically parses the dependencies required by the UserController constructor
$userController = $app->make(UserController::class);

class UserController
{
    public function __construct(UserRepository $users, HttpClient $client, $other = 'default')
    {
    }
}
```

PSR-11
------

[](#psr-11)

Laravel's service container implements the PSR-11 interface. Therefore, you may type-hint the PSR-11 container interface to obtain an instance of the Laravel container:

```
use Psr\Container\ContainerInterface;

$service = $app->get('Service');

```

LISTEN
======

[](#listen)

MIT

Thanks
======

[](#thanks)

[laravel-china](https://laravel.com)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 97.7% 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 ~363 days

Recently: every ~380 days

Total

7

Last Release

1006d ago

Major Versions

1.1.2 → 2.0.02023-07-05

2.0.0 → 3.0.02023-10-02

PHP version history (3 changes)1.0.0PHP &gt;=5.3

2.0.0PHP &gt;=7.2

3.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16079222?v=4)[Lianbo Xu](/maintainers/godruoyi)[@godruoyi](https://github.com/godruoyi)

---

Top Contributors

[![godruoyi](https://avatars.githubusercontent.com/u/16079222?v=4)](https://github.com/godruoyi "godruoyi (43 commits)")[![sunl888](https://avatars.githubusercontent.com/u/9254545?v=4)](https://github.com/sunl888 "sunl888 (1 commits)")

---

Tags

containerlaravellaravel-containerphp5containerlaraveldependency-injectioniocioc-containerlaravel container

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.9k55.5M1.2k](/packages/php-di-php-di)[slince/di

A flexible dependency injection container

20272.1k6](/packages/slince-di)

PHPackages © 2026

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