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

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

mmdm/sim-container
==================

A simple yet nice dependency injection container

v1.2.3(5y ago)120MITPHPPHP &gt;=7.2

Since Aug 2Pushed 5y agoCompare

[ Source](https://github.com/mmdm95/sim-container)[ Packagist](https://packagist.org/packages/mmdm/sim-container)[ RSS](/packages/mmdm-sim-container/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (7)Used By (0)

Simplicity Container
====================

[](#simplicity-container)

A library for dependency injection management.

Features
--------

[](#features)

- Auto wiring
- Singleton construction
- Factory construction
- Method injection
- Both method and array access

Install
-------

[](#install)

**composer**

```
composer require mmdm/sim-container
```

Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.

Just add line below to autoload files:

```
require_once 'path_to_library/autoloader.php';
```

and you are good to go.

How to use
----------

[](#how-to-use)

```
// to instance a container object
$container = new Container();
// here you can define your object and use them
```

Available functions
-------------------

[](#available-functions)

#### Container

[](#container)

#### `set($abstract, $concrete = null, ?string $method_name = null, array $method_parameters = []): Container`

[](#setabstract-concrete--null-string-method_name--null-array-method_parameters---container)

This method store a $concrete with alias of $abstract like class name or any other name.

`Version >= 1.2.0`: Also you can pass the method to be inject as $method\_name and parameters of the method as $method\_parameters. Parameters can be the actual parameter or an abstract to get by container.

Note: You can pass $concrete as $abstract

Note: Parameters are a key value pair like below:

```
parameter_name => your assignment,
index_of_parameter like 0|1|2|... => your assignment,

```

```
// example
'class_type' => CustomClass::class,
1 => 'A parameter',

```

---

```
// store a class
$container->set('log_cls', Logger::class);
// or simply store with Logger::class string
// alias will be the string from Logger::class
$container->set(Logger::class);
// or if you have some works to do and return a
// new instance then use this
$container->set('alias of class', function (Container $c) {
    // do anything you need
    // ...

    // return a new instance of a class
    return new SomeClass();
});

// method injection
$container->set('log_cls', Logger::class, 'info');

// or with parameters
$container->set('log_cls', Logger::class, 'info', [
    'handler' => Handler::class,
    1 => '{level} - {other_parameter} - {message}',
]);
```

#### `get($abstract, ?string $method_name = null, array $method_parameters = [])`

[](#getabstract-string-method_name--null-array-method_parameters--)

This method return a $concrete that stored with alias of $abstract. If it was not exists, it will simply store it first and then resolve that.

`Version >= 1.2.0`: Also you can pass the method to be inject as $method\_name and parameters of the method as $method\_parameters. Parameters can be the actual parameter or an abstract to get by container.

Note: If a stored $concrete has been resolved, it will not resolve again, just return previous resolved $concrete.

Note: Parameters are a key value pair like below:

```
parameter_name => your assignment,
index_of_parameter like 0|1|2|... => your assignment,

```

```
// example
'class_type' => CustomClass::class,
1 => 'A parameter',

```

---

```
// retrieve a class
$container->get('log_cls');
// or
$container->get(NotStoredClass::class);
```

#### `make($abstract, ?string $method_name = null, array $method_parameters = [])`

[](#makeabstract-string-method_name--null-array-method_parameters--)

This method return a $concrete that stored with alias of $abstract. If it was not exists, it will simply store it first and then resolve that.

Parameters are same as `get` method

```
// retrieve new instance of a class
$container->make('log_cls');
// or
$container->make(NotStoredClass::class);
```

#### `has($abstract, string $method_name = null): bool`

[](#hasabstract-string-method_name--null-bool)

This method check if a specific alias $abstract is stored or not. Also you can pass the `$method_name` to check if specific `$abstract`'s method is registered.

```
// check existence of a $abstract
$container->has('log_cls');
// or
$container->has(NotStoredClass::class);
```

#### `unset($abstract, string $method_name = null): Container`

[](#unsetabstract-string-method_name--null-container)

This method remove a stored $abstract. Also you can pass the `$method_name` to remove specific `$abstract`'s method.

```
// remove an $abstract
$container->unset('log_cls');
// or
$container->unset(NotStoredClass::class);
```

#### Singleton accessing

[](#singleton-accessing)

If you need to access container in singleton manner, use `getInstance` static method.

```
$container = Container::getInstance();

// then use all methods
$container->get($abstract);

//...
```

#### Container Inheritance

[](#container-inheritance)

If you want to inherit `Container` (to customize maybe), you can inherit like normal way but if you have multiple class to inherit, then use `ContainerTrait` inside your class and inherit other class as well.

Note: After a trait using, you should type hint `Container`to `YourOtherClass` in closures.

```
class YourOtherClass extends AnotherClass {
    use ContainerTrait;

    // other codes
}

$instance = new YourOtherClass();

// the difference is in [YourOtherClass] instead of [Container]
$instance->set($abstract, function (YourOtherClass $c) {
    // some code
});
```

Array accessing
---------------

[](#array-accessing)

You can use array accessing instead of method accessing:

- `$container[$abstract] = $concrete` instead of `$container->set($abstract, $concrete, ?string $method_name = null, array $method_parameters = [])`.

Accepts $offset as below:

```
  [
    'concrete' => $concrete,
    'method' => [
      'name' => method's name,
      'parameters' => [
        method_parameter1 => CustomClass::class  or  Specified name in container,
        method_parameter2 => AnotherCustomClass::class  or  Specified name in container
      ].
    ],
  ]

```

OR

```
  object(stdClass) {
    'concrete' => $concrete,
    'method' => [
      'name' => method's name,
      'parameters' => [
        method_parameter1 => CustomClass::class  or  Specified name in container,
        method_parameter2 => AnotherCustomClass::class  or  Specified name in container
      ].
    ],
  }

```

OR

```
  An encoded json that has above structure

```

OR

```
  An optional $abstract variable and $concrete/$abstract value

```

---

- `$concrete = $container[$abstract]` instead of `$concrete = $container->get($abstract, ?string $method_name = null, array $method_parameters = [])`.

Accepts $offset as below:

```
  [
    'abstract' => $abstract,
    'method' => [
      'name' => method's name,
      'parameters' => [
        method_parameter1 => CustomClass::class  or  Specified name in container,
        method_parameter2 => AnotherCustomClass::class  or  Specified name in container
      ].
    ],
  ]

```

OR

```
  object(stdClass) {
    'abstract' => $abstract,
    'method' => [
      'name' => method's name,
      'parameters' => [
        method_parameter1 => CustomClass::class  or  Specified name in container,
        method_parameter2 => AnotherCustomClass::class  or  Specified name in container
      ].
    ],
  }

```

OR

```
  An encoded json that has above structure

```

OR

```
  An $abstract variable

```

---

- `isset($container[$abstract])` instead of `$container->has($abstract, string $method_name = null)`.

Accepts $offset as below:

```
  [
    'abstract' => $abstract,
    'method' => [
      'name' => method's name,
    ],
  ]

```

OR

```
  object(stdClass) {
    'abstract' => $abstract,
    'method' => [
      'name' => method's name,
    ],
  }

```

OR

```
  An encoded json that has above structure

```

OR

```
  An $abstract variable

```

---

- `unset($container[$abstract])` instead of `$container->unset($abstract, string $method_name = null)`.

Accepts $offset as below:

```
  [
    'abstract' => $abstract,
    'method' => [
      'name' => method's name,
    ],
  ]

```

OR

```
  object(stdClass) {
    'abstract' => $abstract,
    'method' => [
      'name' => method's name,
    ],
  }

```

OR

```
  An encoded json that has above structure

```

OR

```
  An $abstract variable

```

License
=======

[](#license)

Under MIT license.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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

Every ~15 days

Total

6

Last Release

2039d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d955ebaae3fe602e6ad26c16422f6ab25a61a436fd7f08425a5be5c73ef9025c?d=identicon)[mmdm95](/maintainers/mmdm95)

---

Top Contributors

[![mmdm95](https://avatars.githubusercontent.com/u/26489185?v=4)](https://github.com/mmdm95 "mmdm95 (49 commits)")

### Embed Badge

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

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

PHPackages © 2026

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