PHPackages                             jhonymiler/di - 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. [Framework](/categories/framework)
4. /
5. jhonymiler/di

ActiveLibrary[Framework](/categories/framework)

jhonymiler/di
=============

Dependency Injection Container

v1.0.0(2y ago)14MITPHP

Since Jul 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/jhonymiler/di)[ Packagist](https://packagist.org/packages/jhonymiler/di)[ RSS](/packages/jhonymiler-di/feed)WikiDiscussions main Synced 1mo ago

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

Container Usage Documentation

Container Usage Documentation
=============================

[](#container-usage-documentation)

The **Container** class is a basic dependency injection container that allows you to manage dependencies and resolve them automatically within your application. It provides a convenient way to handle object instantiation and dependency injection, making your code more modular and maintainable.

Getting Started
---------------

[](#getting-started)

To begin using the Container class, you first need to include the relevant PHP files and create an instance of the container:

```
    use Tests\Core\Container;
    require 'vendor/autoload.php';
    $container = Container::getInstance();
```

Binding Classes to the Container
--------------------------------

[](#binding-classes-to-the-container)

You can bind classes or closures to the container using the `bind` method. When you request an instance from the container, it will automatically resolve the bound dependencies for you.

```
    // Binding a customized MysqlDb instance to the container
    $container->bind(MysqlDb::class, function () {
        // Custom configuration for MysqlDb, if needed
        $db = new Db(/*...*/);
        return new MysqlDb($db);
    });
```

Resolving Dependencies
----------------------

[](#resolving-dependencies)

When you call the `get` method with a class name, the container will resolve and return an instance of that class, along with its dependencies.

```
    // Retrieving an instance of MysqlDb from the container
    $mysqlDb = $container->get(MysqlDb::class);
    // Retrieving an instance of User from the container
    $user = $container->get(User::class);
```

Dependency Injection
--------------------

[](#dependency-injection)

The container can automatically inject dependencies into closures when using the `call` method. This allows you to resolve dependencies for a specific function or method.

```
    // Using the call method to automatically resolve dependencies for a closure
    $container->call(function (Logger $logger, EntityManager $em) use ($user) {
        // Here, the logUserData method of the User class will be called with resolved dependencies
        $user->logUserData($logger);
        $data = $em->getData();
        var_dump($data);
    });
```

Error Handling
--------------

[](#error-handling)

If a class is not found in the container, or if there are unresolved dependencies, the Container class will throw an `Exception`. It is important to handle these exceptions properly in your application to ensure smooth operation.

```
    try {
        $invalidInstance = $container->get(NonExistentClass::class);
    } catch (Exception $e) {
        // Handle the exception here
    }
```

Conclusion
----------

[](#conclusion)

The Container class simplifies the management of dependencies in your PHP application. By binding classes and closures, you can easily resolve instances with their dependencies, making your code more organized and easier to maintain.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

1029d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/42965ddf0e0b82fb41857e7c55a5f7e6d8a1b9eead8d0e9eb4956bf35fcc1a0b?d=identicon)[jhonymiler](/maintainers/jhonymiler)

---

Top Contributors

[![jhonymiler](https://avatars.githubusercontent.com/u/18699320?v=4)](https://github.com/jhonymiler "jhonymiler (2 commits)")

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

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