PHPackages                             mohamed-amine/ioc-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. mohamed-amine/ioc-container

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

mohamed-amine/ioc-container
===========================

Inversion of control container

v0.8.3(1y ago)4409[1 PRs](https://github.com/Amin-Cheribet/IOC-Container/pulls)2MITPHPPHP ^8.3CI passing

Since Jan 20Pushed 3w ago1 watchersCompare

[ Source](https://github.com/Amin-Cheribet/IOC-Container)[ Packagist](https://packagist.org/packages/mohamed-amine/ioc-container)[ RSS](/packages/mohamed-amine-ioc-container/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (1)Versions (27)Used By (2)

[![Build Status](https://camo.githubusercontent.com/2a843bb48ffe914475190152d0831b0185dc89ddecad75cc17ae40ea88d980c2/68747470733a2f2f7472617669732d63692e6f72672f4d6f68616d6564416d696e652d432f494f432d436f6e7461696e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/MohamedAmine-C/IOC-Container)

How to install:
===============

[](#how-to-install)

### Via composer

[](#via-composer)

`composer require mohamed-amine/ioc-container`

What can it do:
===============

[](#what-can-it-do)

- create instances and resolve their dependencies automatically.
- resolve dependencies from types( like Interfaces) if they are registered.
- create instances from registred services locators.
- bind existing instances into the container (can be used for service providers).
- call instances from the container anywhere in your application.

How to use it:
==============

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

### Create the contianer:

[](#create-the-contianer)

in order to use all the features we need to create a container first

```
  IOC\IOC::createContainer();
```

### Create an instance in the container:

[](#create-an-instance-in-the-container)

- to create an instance and resolve it's dependencies automatically:

```
  IOC\IOC::container()->build('namespace\MyClass');
```

This will create the MyClass object and create all of it's dependencies recursively for example:

```
// instead of doing this
new MyClass(new ClassA(), new ClassB());
// you can just do this and it will create ClassA & ClassB and pass them automatically
IOC\IOC::container()->build('namespace\MyClass');
```

In order for this to work you need to use type hinting in MyClass constructor :

```
...
public function __constructor(ClassA $classa, ClassB $classb) {...}
...
```

- if the instance require arguments we should pass them in an array as a second argument of 'build()' (note that automatic dependencies resolving can't be used in this case):

```
  IOC\IOC::container()->build('namespace\MyClass', $argument1, $argument2);
```

### Bind instances into the container:

[](#bind-instances-into-the-container)

To bind an existing instance into the container

```
  IOC\IOC::bind('MyClass',function() {
    return new namespace\MyClass();
  });
```

Now we will be able to access our instance anywhere in the application like this:

```
  IOC\IOC::container()->MyClass;
  // or
  IOC\IOC::container()->get('MyClass');
```

### Build instances from services locators (short names):

[](#build-instances-from-services-locators-short-names)

We can define service locators using the regiter method

```
  IOC\IOC::container()->register('MyClass', namespace\MyClass::class);
```

Then we can build an instance using this service locator

```
  IOC\IOC::container()->build('MyClass');
```

### Registering Types:

[](#registering-types)

Types are registered to help the container to resolve classes dependencies, for example if a class A have a dependency of Type SomeInterface which is an interface, we will have to register this type first in order to be able to resolve it:

```
  IOC\IOC::container()->registerType('SomeInterface', Namespace\SomeClass::class);
```

### Calling instances from the container:

[](#calling-instances-from-the-container)

we can call instances from the container using 2 methods

```
  IOC\IOC::container()->MyInstance;
  // Or
  IOC\IOC::container()->get('MyInstance');
```

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance68

Regular maintenance activity

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% 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 ~122 days

Recently: every ~210 days

Total

20

Last Release

704d ago

PHP version history (6 changes)0.0.1PHP &gt;=7.0

v0.5.0PHP &gt;=7.1.6

v0.7.0PHP &gt;=7.4.0

v0.8.0PHP ^8.0

0.8.x-devPHP ^8.2

v0.8.2PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e5dc981359178c6feb2bd30c235b1170bb046b2014835eaa6dbe4c2dca36326?d=identicon)[amine Cheribet](/maintainers/amine%20Cheribet)

---

Top Contributors

[![Amin-Cheribet](https://avatars.githubusercontent.com/u/7945706?v=4)](https://github.com/Amin-Cheribet "Amin-Cheribet (27 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

### Embed Badge

![Health badge](/badges/mohamed-amine-ioc-container/health.svg)

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

###  Alternatives

[ramsey/devtools

A Composer plugin to aid PHP library and application development.

7134.7k26](/packages/ramsey-devtools)[jimbojsb/workman

PHP process forking &amp; daemonizing library

608.8k](/packages/jimbojsb-workman)

PHPackages © 2026

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