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

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

fkeloks/simple-container
========================

A simple psr-11 container for PHP &gt;= 7.0

v1.0.0(8y ago)113MITPHPPHP &gt;=7.0.0

Since Sep 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/fkeloks/simple-container)[ Packagist](https://packagist.org/packages/fkeloks/simple-container)[ RSS](/packages/fkeloks-simple-container/feed)WikiDiscussions master Synced 2mo ago

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

PSR-11 Simple container
=======================

[](#psr-11-simple-container)

[![Build Status](https://camo.githubusercontent.com/54f5a9fa076be751ca98737f8bf77d72ffba6980e97cfce95e60137144df9427/68747470733a2f2f7472617669732d63692e6f72672f666b656c6f6b732f73696d706c652d636f6e7461696e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/fkeloks/simple-container)

A simple psr-11 compatible container.
By Florian B. (Alias fkeloks)

Installation :
--------------

[](#installation-)

With [Composer](https://getcomposer.org/):

```
composer require fkeloks/simple-container

```

How to use it :
---------------

[](#how-to-use-it-)

### Declare configuration:

[](#declare-configuration)

Example:

```
$configuration = [
    FakeClassA::class => FakeClassA::class,
    FakeClassB::class => FakeClassA::class,
    'FakeC'           => FakeClassC::class,
    'FakeD'           => [
        'class'  => FakeClassD::class,
        'params' => ['A', 'B']
    ]
]

/*
 * get(FakeClassA::class) will return FakeClassA class
 * |-> But this statement is useless, the container will understand automatically.
 *
 * get(FakeClassB::class) will return FakeClassA class
 * |-> Because the configuration overrides the name of the class.
 *
 * get('FakeC') will return FakeClassC class
 *
 * get('FakeD') will return FakeClassD class withs constructor parameters 'A' and 'B'
 */
```

---

### Creating the container from the containerBuilder:

[](#creating-the-container-from-the-containerbuilder)

*We consider that $configuration has been instantiated above.*

```
use SimpleContainer\ContainerBuilder;

ContainerBuilder::build($configuration);
$container = ContainerBuilder::getContainer();
```

```
use SimpleContainer\ContainerBuilder;

// Short syntax
$container = ContainerBuilder::build($configuration)::getContainer();
```

Once the constructor is built, the container can be retrieved anywhere with:

```
use SimpleContainer\ContainerBuilder;

$container = ContainerBuilder::getContainer();
// The container will be configured with the previous `ContainerBuilder::build()`
```

If necessary, the container has a `destroy ()` method to destroy the previous `build ()`:

```
ContainerBuilder::destroy();
```

---

### Get and make methods:

[](#get-and-make-methods)

#### Get:

[](#get)

The `get` function will return the desired instance.
At the first call, the instance will be cached.
If the instance is present in the cache, the cached instance will be returned.

Examples:

```
$classA = $container->get('FakeA');
$classA = $container->get(FakeClassB::class);
```

### Make:

[](#make)

The `make` function returns the desired instance.
This function does not take into account the cache in the return of the instance.
However, the returned instance will still be cached for the next `get ()`

Examples:

```
$classB = $container->make('FakeB');
$classC = $container->make(FakeClassC::class);
```

Examples:
---------

[](#examples)

Example 1:

```
class Hello() {

    private $name;
    private $pseudo;

    public function __construct($name, $pseudo) {
        $this->name   = $name;
        $this->pseudo = $pseudo;
    }

    public function sayHello() {
        return "Hello {$this->pseudo} ({$this->name}) !";
    }
}

SimpleContainer\ContainerBuilder::build([
    'helloClass' => [
        'class'  => Hello::class,
        'params' => ['James', 'Jojo']
    ]
])

$container = SimpleContainer\ContainerBuilder::getContainer();

$helloClass = $container->get('helloClass');
echo $helloClass->sayHello();

/*
 * The result will be: "Hello Jojo (James) !"
 */
```

Example 2:

```
SimpleContainer\ContainerBuilder::build([
    'classA' => ClassA::class
])

$container = SimpleContainer\ContainerBuilder::getContainer();

$classA = $container->get('classA'); // A new instance of ClassA is generated
$classA = $container->get('classA'); // Class A has been cached, so the same instance is returned

$classA = $container->make('classA');
// |-> The make function does not take the cache into account, so a new instance of A is generated
```

Further information
-------------------

[](#further-information)

In the kind of configuration:

```
SimpleContainer\ContainerBuilder::build([
    'helloClass' => [
        'class'  => Hello::class,
        'params' => ['James', 'Jojo']
    ]
])
```

The constructor will receive 2 distinct variables. ('James', and 'Jojo')
Whatever type of variable to pass to the constructor, `params` must be an array.

Examples:

```
'params' => ['yeah']     // string
'params' => [true]       // boolean
'params' => [['A', 'B']] // array
'params' => [123456789]  // integer
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

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

3175d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5241c97d7b41e2e04e77b03d774fe747da9917c273f62975e670f0afaa89bbde?d=identicon)[fkeloks](/maintainers/fkeloks)

---

Top Contributors

[![fkeloks](https://avatars.githubusercontent.com/u/16477784?v=4)](https://github.com/fkeloks "fkeloks (8 commits)")

---

Tags

composercontainerspsr-11simple

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)
