PHPackages                             g4/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. g4/di

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

g4/di
=====

g4 dependencies injection container based on Pimple

1.0.2(4y ago)075.0k↓30.3%23MITPHPPHP &gt;=5.3.3

Since Apr 27Pushed 4y ago11 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (9)Used By (3)

DI
==

[](#di)

> DI - dependencies injection container - singleton Pimple wrapper

- easy access by a method not by an array property
- no need to remember DI array keys (or go back to the DI class to look) every time you need something
- type hinting

Install
-------

[](#install)

Using Composer and Packagist

```
composer require g4/di
```

Usage
-----

[](#usage)

Services are defined by anonymous functions that returns an instance of an object. Define all services in one DI Container class inside your application:

```
namespace MyNamespace;

use G4\DI\Container;

class DI extends Container
{
    /**
     * @return \MyNamespace\MyConfig
     */
    public static function configInstance()
    {
        return self::registerShare(function (DI $c) {
            return new \MyNamespace\MyConfig();
        });
    }

    /**
     * @return \MyNamespace\MyClass
     */
    public static function myClassInstance()
    {
        return self::registerFactory(function (DI $c) {
            return new \MyNamespace\MyClass($c::configInstance());
        });
    }
}
```

Methods

- registerFactory($callable) - Register a service that will each time return new instance of it
- registerShare($callable) - Register a service that will each time return the same instance of it

Using the defined services

```
use MyNamespace\DI;

$myClass = DI::myClassInstance();

// the above call is equivalent to:
// $myConfig = new \MyNamespace\MyConfig();
// $myClass = new \MyNamespace\MyClass($myConfig);
```

Development
-----------

[](#development)

### Install dependencies

[](#install-dependencies)

```
$ make install

```

### Run tests

[](#run-tests)

```
$ make test

```

License
-------

[](#license)

(The MIT License) see LICENSE file for details...

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~482 days

Recently: every ~705 days

Total

7

Last Release

1510d ago

Major Versions

0.2.0 → 1.0.02015-09-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/12ceafbc629c3019d7cd78dfec322d694f44e0df8741bc6044f4acbf99964ff8?d=identicon)[g4code](/maintainers/g4code)

---

Top Contributors

[![dsamardzija](https://avatars.githubusercontent.com/u/366252?v=4)](https://github.com/dsamardzija "dsamardzija (7 commits)")[![gomboc](https://avatars.githubusercontent.com/u/1145653?v=4)](https://github.com/gomboc "gomboc (6 commits)")[![ppavlovic](https://avatars.githubusercontent.com/u/2664974?v=4)](https://github.com/ppavlovic "ppavlovic (3 commits)")[![vb-c-plicity](https://avatars.githubusercontent.com/u/101137972?v=4)](https://github.com/vb-c-plicity "vb-c-plicity (2 commits)")[![rdohms](https://avatars.githubusercontent.com/u/94331?v=4)](https://github.com/rdohms "rdohms (1 commits)")

---

Tags

didependenciespimple

### Embed Badge

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

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

###  Alternatives

[level-2/dice

A minimalist Dependency injection container (DIC) for PHP. Please note: 3.0+ is only compatible with PHP 7.0. The 2.0 branch is compatbile with PHP 5.6.

437730.3k17](/packages/level-2-dice)[hyperf/di

A DI for Hyperf.

182.8M594](/packages/hyperf-di)[mouf/pimple-interop

This project is a very simple extension to the Pimple microframework. It adds to Pimple compatibility with the container-interop APIs.

102.4M2](/packages/mouf-pimple-interop)[rochamarcelo/cake-pimple-di

A cakephp plugin for dependency injection based on Pimple library

12176.8k](/packages/rochamarcelo-cake-pimple-di)[symfony-bundles/bundle-dependency

Symfony BundleDependency Component

19135.9k7](/packages/symfony-bundles-bundle-dependency)

PHPackages © 2026

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