PHPackages                             abmmhasan/di-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. abmmhasan/di-container

Abandoned → [infocyph/intermix](/?search=infocyph%2Fintermix)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

abmmhasan/di-container
======================

Simple dependency injector

1.00(5y ago)322MITPHPPHP &gt;=7.0

Since Dec 31Pushed 4y ago1 watchersCompare

[ Source](https://github.com/abmmhasan/DI-Container)[ Packagist](https://packagist.org/packages/abmmhasan/di-container)[ Docs](https://abmmhasan.github.io/DI-Container/)[ RSS](/packages/abmmhasan-di-container/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

DI Container
============

[](#di-container)

[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)

This library, resolves constructor &amp; method dependency on the fly (also for closure). Check examples below.

### Repository archived/abandoned.

[](#repository-archivedabandoned)

Suggested to use  instead!

Prerequisites
-------------

[](#prerequisites)

Language: PHP 7.0/+

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

[](#installation)

```
composer require abmmhasan/di-container

```

Usage
-----

[](#usage)

### Example 01: With additional parameter

[](#example-01-with-additional-parameter)

```
/**
* A test class where we resolving dependency for
* both constructor and defined method
*/
class TestClass
{
    public function __construct(Sample1 $sample, $id)
    {
        return [$sample->all(),$id];
    }

    public function getRequest(Sample2 $sample, $pid, $sid)
    {
        return [$sample->all(),$pid,$sid];
    }
}

/**
* Pass the class as first parameter
* In second parameter pass the value as comma separated which will be
* resolved to class __construct
*/
$class = new Container(TestClass::class,23); // TestClass: Class we resolving, 23: $id param
// or,
$class = initiate(TestClass::class,23);
/**
* Afterwards we call any methods of that class
* 'getRequest()' is a method of 'TestClass' that we are calling.
* Extra parameter can be sent as comma separated, which will be resolved to given method
*/
$value = $class->getRequest(34,43);
```

### Example 02: Without additional parameter

[](#example-02-without-additional-parameter)

```
/**
* A test class where we resolving dependency for
* both constructor and defined method
*/
class TestClass
{
    public function __construct(Sample1 $sample)
    {
        return [$sample->all()];
    }

    public function getRequest(Sample2 $sample)
    {
        return [$sample->all()];
    }
}

/**
* Only send parameter if required
*/
$class = new Container(TestClass::class); // TestClass: Class we resolving
// or,
$class = initiate(TestClass::class);
/**
* Same as above
*/
$value = $class->getRequest();
```

### Example 03: Closure

[](#example-03-closure)

```
$myClosure = function (Request $request, $test, $rest) {
                     print_r($request);
                     echo "I'm inside[$test,$rest]";
                 };
$class = new Container($myClosure, 23, 34); // Pass the closure
// or,
$class = initiate($myClosure, 23, 34);
```

### Example 04: I don't need any dependency resolution

[](#example-04-i-dont-need-any-dependency-resolution)

```
/**
* From example 02 (same for 01 but not applicable for 03: Closure)
 */
$class = new Container(TestClass::class); // TestClass: Class we resolving
// or,
$class = initiate(TestClass::class);
/**
* Add this additional call before doing any method call
*/
$class->_noInject();
/**
* Now do calls as usual
 */
$value = $class->getRequest();
```

Support
-------

[](#support)

Having trouble? Create an issue!

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

2009d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/33b750b84ab22f2038ef9b90ee48f2fcdaab6b5698e9f956a89a152466200b63?d=identicon)[abmmhasan](/maintainers/abmmhasan)

---

Top Contributors

[![abmmhasan](https://avatars.githubusercontent.com/u/7711128?v=4)](https://github.com/abmmhasan "abmmhasan (18 commits)")

---

Tags

closuredependency-injectiondidi-containerphp

### Embed Badge

![Health badge](/badges/abmmhasan-di-container/health.svg)

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

PHPackages © 2026

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