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

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

johnroyer/php-easy-container
============================

an easy composer

v1.1.1(6y ago)0391[2 issues](https://github.com/johnroyer/php-easy-container/issues)MITPHPPHP &gt;=7.2CI failing

Since Sep 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/johnroyer/php-easy-container)[ Packagist](https://packagist.org/packages/johnroyer/php-easy-container)[ RSS](/packages/johnroyer-php-easy-container/feed)WikiDiscussions master Synced 3d ago

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

PHP-Easy-Container
==================

[](#php-easy-container)

[![Build Status](https://camo.githubusercontent.com/a8ee57a274f604f96fbeeddbfe61249471e85faafb318fd4ca61cb4581e3adb7/68747470733a2f2f7472617669732d63692e6f72672f6a6f686e726f7965722f7068702d656173792d636f6e7461696e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/johnroyer/php-easy-container)[![Coverage Status](https://camo.githubusercontent.com/1498554ea2c3a3983da349bd8a3d9ec8ed33170918b1bc61e7c6750f90524e84/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a6f686e726f7965722f7068702d656173792d636f6e7461696e65722f62616467652e737667)](https://coveralls.io/github/johnroyer/php-easy-container)

An implement for singleton and some features.

Requirement
-----------

[](#requirement)

- PHP &gt;= 5.6

Installation
------------

[](#installation)

using composer:

```
composer require johnroyer/php-easy-container
```

Simple Usage
------------

[](#simple-usage)

Put whatever you want into container:

```
use \Zeroplex\Container\Container;

$c = new Container;

// set value as singleton
$c['pi'] = 3.14159;
$c['db'] = new PDO(
    'mysql:dbname=mydb;host=localhost',
    'user',
    'password'
);
```

Get things out from container:

```
$c['pi'];  // 3.14159
$c['db'];  // object(PDO)
```

Singleton
---------

[](#singleton)

If you use `ArrayAccess` interfaces to access the data from container, container will treat them as sinleton, as example ablove.

You can also use method `singleton()` to put data into container:

```
$c->singleton('db') = new PDO(
    'mysql:dbname=mydb;host=localhost',
    'user',
    'password'
);

$c->get('db');  // object(PDO)
```

You can also put a global variable into container:

```
$c->singleton('config') = new Config(
    APP_ROOT . '/config'
);

$c['config']['app.name'];
```

### Late initialize

[](#late-initialize)

Sometimes, you are not sure if an DB connection should initialize while program start up. Maybe connect to DB when it is really needed is a better idea.

Use a `Closure` to let container known you want to initialize it later:

```
$c['db'] = function () {
    return new PDO(
        'mysql:dbname=test;host=localhost',
        'user',
        'password'
    );
};

$c->get('db');  // new PDO if and only if someone get it
                // object(PDO)
```

Provide
-------

[](#provide)

Container can contains things with states, can also contains things stateless. `provide()` method stores bussiness logic or workflow which is stateless.

```
$c->provide('pi', 3.14159265359);
$c['pi'];  // 3.14159265359

$c->provide('nowDate', function() {
    // always return special format of date
    return (new DateTime())
        ->format('Y-m-d');
});
$c->['nowDate'];  // "2017-12-01"
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 94.9% 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 ~84 days

Recently: every ~171 days

Total

10

Last Release

2391d ago

Major Versions

v0.10.0 → 5.6.x-dev2017-10-27

PHP version history (2 changes)5.6.x-devPHP &gt;=5.6.0

1.1PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/134a7921f61f2b847c6f81e18d0cea923d1b877e2d86ff4f4322a99c4642c147?d=identicon)[johnroyer](/maintainers/johnroyer)

---

Top Contributors

[![johnroyer](https://avatars.githubusercontent.com/u/114491?v=4)](https://github.com/johnroyer "johnroyer (56 commits)")[![passionFarmer64](https://avatars.githubusercontent.com/u/32559397?v=4)](https://github.com/passionFarmer64 "passionFarmer64 (3 commits)")

---

Tags

containerphpsimple

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[davidgorges/color-contrast

A tiny library to find color combinations with a contrast threshold

10550.4k](/packages/davidgorges-color-contrast)

PHPackages © 2026

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