PHPackages                             gixx/worstpractice-dependency-injection - 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. gixx/worstpractice-dependency-injection

ActiveLibrary

gixx/worstpractice-dependency-injection
=======================================

A simple dependency injection container

1.1.0(3y ago)24[1 PRs](https://github.com/Gixx/worstpractice-dependency-injection/pulls)MITPHPPHP &gt;=8.2

Since Apr 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Gixx/worstpractice-dependency-injection)[ Packagist](https://packagist.org/packages/gixx/worstpractice-dependency-injection)[ Docs](http://www.worstpractice.dev)[ RSS](/packages/gixx-worstpractice-dependency-injection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (9)Versions (7)Used By (0)

The worstpractice.dev presents
==============================

[](#the-worstpracticedev-presents)

DIY Dependency Injection
------------------------

[](#diy-dependency-injection)

[![PHP Version](https://camo.githubusercontent.com/91cb649feb797bb507583f5f4e88d0727695b25c0a7265b8b1c7448848b13ef9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322d626c7565)](https://www.php.net/ChangeLog-8.php)[![Build Status](https://camo.githubusercontent.com/2532834c6ce89a15a49cdd08b5b54b5d4f2934f318e4f2039bff9bd12326924f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275696c642d4e2f412d6f72616e6765)](https://camo.githubusercontent.com/2532834c6ce89a15a49cdd08b5b54b5d4f2934f318e4f2039bff9bd12326924f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275696c642d4e2f412d6f72616e6765)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/70b2abdd56ee7731a7ba5d71da97bca237e633026e10bfbe42606c6ccc44ebca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5363727574696e697a65722d4e2f412d6f72616e6765)](https://camo.githubusercontent.com/70b2abdd56ee7731a7ba5d71da97bca237e633026e10bfbe42606c6ccc44ebca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5363727574696e697a65722d4e2f412d6f72616e6765)[![PHStan](https://camo.githubusercontent.com/93f1287c33ef0c76eddaff896389a877552ef199d61adfc7315e97f1ce8fe96d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d7061737365642d73756363657373)](https://camo.githubusercontent.com/93f1287c33ef0c76eddaff896389a877552ef199d61adfc7315e97f1ce8fe96d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d7061737365642d73756363657373)[![Code Coverage](https://camo.githubusercontent.com/5d66769788d6b975b0f95add6734d2715c5bb1b6453557a2a5d59417f3c3ce24/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d3130305f2532352d73756363657373)](https://camo.githubusercontent.com/5d66769788d6b975b0f95add6734d2715c5bb1b6453557a2a5d59417f3c3ce24/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d3130305f2532352d73756363657373)[![Packagist Package](https://camo.githubusercontent.com/d982c7d404924545f4a814a485a21780d1e0a5276e7ff96c6f0e4cebde0c5543/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f6e616d652f676978782f776f72737470726163746963652d646570656e64656e63792d696e6a656374696f6e)](https://packagist.org/packages/gixx/worstpractice-dependency-injection)[![Packagist Downloads](https://camo.githubusercontent.com/9a443a490356411ca8677288d86c490a115fd518da3d7d7d0492d15fa5c6a5bf/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f64742f676978782f776f72737470726163746963652d646570656e64656e63792d696e6a656374696f6e)](https://packagist.org/packages/gixx/worstpractice-dependency-injection)

The complete source code for the series of articles [DIY Dependency Injection Container](https://worstpractice.dev/backend/diy-dependency-injection-container) part 1, 2 and 3.

### Purpose

[](#purpose)

The only purpose is practicing:

- PHP 7.4, 8.0, 8.1 and 8.2 features
- keep coding standards
- write clean code
- write strict-typed code
- Unit testing

Although, I believe it works like any other DIC, I don't recommend to use it in production. Unfortunately the code quality checks on the Scrutinizer CI side don't yet support PHP 8.2.

### Installation

[](#installation)

To add this package to your project, just get it via composer:

```
composer require gixx/worstpractice-dependency-injection

```

### Usage

[](#usage)

To use it, you will need only a configuration as in the example:

```
namespace MyNamespace;

use WorstPractice\Component\DependencyInjection\ConfigParser\ArrayParser;
use WorstPractice\Component\DependencyInjection\ServiceLibrary;
use WorstPractice\Component\DependencyInjection\Container;

$config = [
    'ServiceAlias' => [
        'class' => \Namespace\To\MyClass::class,
        'arguments' => [
            \Namespace\To\OtherClassInterface::class,
            'literalParameter' => 1234,
            'otherLiteralParameter' => false
        ],
        'shared' => false
    ],
    \Namespace\To\OtherClassInterface::class => [
        'class' => \Namespace\To\OtherClass::class,
        'shared' => true
    ],
    \DateTimeZone::class => [
        'arguments' => [
            'param' => 'Europe/Berlin'
        ],
        'shared' => true
    ],
    \DateTime::class => [
        'calls' => [
            ['setTimezone', [\DateTimeZone::class]]
        ],
        'shared' => true
    ],
    'Auth' => [
        // empty, will be determined later
    ],
    'OtherServiceAlias' => [
        'inherits' => 'ServiceAlias',
        'calls' => [
            ['someMethod', ['parameter1' => 4543, 'parameter2' => [0, 1, 2], \DateTime::class]]
        ],
        'shared' => true
    ],
    'LoginController' => [
        'class' => \Namespace\To\Controller\Login:class,
        'arguments' => [
            'Auth',
            'OtherServiceAlias'
        ]
    ]
];

$container = new Container(new ServiceLibrary(new ArrayParser()), $config);

$authService = $_ENV['environment'] === 'dev'
    ? new \Namespace\To\DebugAuthService()
    : new \Namepace\To\Strict\AuthenticationService();
$isShared = true;

$container->set('Auth', $authService, $isShared);

$controller = $container->get('LoginController');
```

This DIC will instantiate any class only when it is requested or being referenced by a requested class. It also supports adding instance into the DIC. It comes in handy when the script needs an instance based on some calculation.

### Testing

[](#testing)

The package contains a simple Docker setup to be able to run tests. For this you need only run the following:

```
docker-compose up -d
docker exec -it worstpractice-dependency-injection-php-fpm php composer.phar install
docker exec -it worstpractice-dependency-injection-php-fpm php composer.phar check

```

The following tests will run:

- PHP lint
- PHP Mess Detector
- PHP Unit
- PHPStan (max level, no ignored Errors)

[![PHP Unit](docs/images/unit.gif)](docs/images/unit.gif)

[![PHPStan](docs/images/stan.gif)](docs/images/stan.gif)

The following tests form the PHP 7.4 version are now ignored, since they don't yet have PHP 8.2 support:

- PHP-CS-Fixer
- PHP Code Sniffer

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 95% 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 ~310 days

Total

4

Last Release

1276d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.4

1.1.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c2c2a0d3ff5e9ea9bfd505b32fb0db6d5d4763fc26aef3984c0dd71214909c0?d=identicon)[Gixx](/maintainers/Gixx)

---

Top Contributors

[![Gixx](https://avatars.githubusercontent.com/u/87073?v=4)](https://github.com/Gixx "Gixx (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gixx-worstpractice-dependency-injection/health.svg)

```
[![Health](https://phpackages.com/badges/gixx-worstpractice-dependency-injection/health.svg)](https://phpackages.com/packages/gixx-worstpractice-dependency-injection)
```

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[neos/flow

Flow Application Framework

862.0M449](/packages/neos-flow)[api-platform/state

API Platform state interfaces

223.4M57](/packages/api-platform-state)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)[symfony/json-streamer

Provides powerful methods to read/write data structures from/into JSON streams.

14440.0k8](/packages/symfony-json-streamer)[rubix/server

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

632.3k](/packages/rubix-server)

PHPackages © 2026

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