PHPackages                             koded/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. koded/container

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

koded/container
===============

A simple Dependency Injection Container with application modules support

3.0.1(4y ago)13581BSD-3-ClausePHPPHP ^8.1CI failing

Since Sep 10Pushed 4y ago1 watchersCompare

[ Source](https://github.com/kodedphp/container)[ Packagist](https://packagist.org/packages/koded/container)[ Docs](https://github.com/kodedphp/container)[ RSS](/packages/koded-container/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (4)Versions (13)Used By (1)

Dependency Injection Container - Koded
--------------------------------------

[](#dependency-injection-container---koded)

[![CI](https://github.com/kodedphp/container/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/kodedphp/container/actions/workflows/unit-tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/90966995e5012f7a345f67687ffafc31a57697853b829a4afdab87c2c71bc25f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6f6465642f636f6e7461696e65722e737667)](https://packagist.org/packages/koded/container)[![Minimum PHP Version: 8.1](https://camo.githubusercontent.com/183804d09fec16ca7b6209b007250b7d8db1b915042feb093a9f20e6e1f25359/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e312d3838393242462e737667)](https://php.net/)

`koded/container` is an OOP application bootstrapping and wiring library. In other words, `Koded\DIContainer` implements a **design pattern** called **Dependency Inversion**. The main principle of DIP is to separate the behavior from dependency resolution.

```
composer require koded/container
```

Example
-------

[](#example)

Let's look at a blog application that has

- interfaces for the database repositories and corresponding implementations
- a shared PDO instance
- a service class for the blog content fetching
- a handler class that maps the request method

```
use PDO;

interface PostRepository {
    public function findBySlug(string $slug);
}

interface UserRepository {
    public function findById(int $id);
}

class DatabasePostRepository implements PostRepository {
    private $pdo;
    public function __construct(PDO $pdo) {
        $this->pdo = $pdo;
    }
    public function findBySlug(string $slug) {
        // $this->pdo ...
    }
}

class DatabaseUserRepository implements UserRepository {
    private $pdo;
    public function __construct(PDO $pdo) {
        $this->pdo = $pdo;
    }
    public function findById(int $id) {
        // $this->pdo ...
    }
}
```

Somewhere we may have a service class that uses the dependent repositories:

```
class PostService {
    private $post, $user;
    public function __construct(PostRepository $post, UserRepository $user) {
        $this->post = $post;
        $this->user = $user;
    }

    // a service method that uses the post and user repository instances
    public function findBlogPostBySlug(string $slug) {
        $post = $this->post->findBySlug($slug);
        $user = $this->user->findById($post->userId());
        // ... do something with the results, create a result data structure...
    }
}
```

Then somewhere we might have a handler/controller that asks for its own dependencies:

```
class BlogHandler {
    public function get(ServerRequestInterface $request, PostService $service): ResponseInterface {
        $slug = slugify($request->getUri()->getPath());
        $post = $service->findBlogPostBySlug($slug);

        // some PSR-7 compatible response object
        return new ServerResponse($post);
    }
}
```

### Wire All The Things

[](#wire-all-the-things)

This is the bootstrapping / wiring application module (or container's "configuration" class) where all known dependencies are binded and shared

```
class BlogModule implements DIModule {
    public function configure(DIContainer $container): void {
        // bind interfaces to concrete class implementations
        $container->bind(PostRepository::class, DatabasePostRepository::class);
        $container->bind(UserRepository::class, DatabaseUserRepository::class);
        $container->bind(ServerRequestInterface::class, /*some PSR-7 server request class name*/);

        // share one PDO instance
        $container->singleton(PDO::class, ['sqlite:database.db']);
    }
}
```

And finally in the dispatcher file, we process the request

```
// index.php

// (resolved through an HTTP router or other means)
$handler = BlogHandler::class;
$method = 'get';

// by invoking the container
$response = (new DIContainer(new BlogModule))([$handler, $method]);

// we have a `$response` object to output the content
// ex. `echo $response->getBody()->getContents();`
```

The container implements the [\_\_invoke()](https://php.net/manual/en/language.oop5.magic.php#object.invoke) method, so the instance can be used as a function:

```
$container('method', ['arg1', 'arg2', ...]);
```

> To be continued...

Code quality
------------

[](#code-quality)

[![Code Coverage](https://camo.githubusercontent.com/9a9013302ef624dc40eef29baf44496161c4d5506e714acce0c4b5bc8f80f702/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f6465647068702f636f6e7461696e65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/kodedphp/container/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6b12fa7675573812ed2aa03657001fa72f2ad93b8d9ea11f54759c468ac398fb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f6465647068702f636f6e7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/kodedphp/container/?branch=master)[![Infection MSI](https://camo.githubusercontent.com/dd2e6624f93ffd01bd1e832ec3227a5ea04ff9a63a7c3b7a8c43b1beb56f1e60/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532466b6f646564706870253246636f6e7461696e65722532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/kodedphp/container/master)

```
vendor/bin/infection --threads=4
vendor/bin/phpbench run --report=default
vendor/bin/phpunit
```

License
-------

[](#license)

[![Software license](https://camo.githubusercontent.com/b3775a2de17853a90995faa104f941eef3ad3c40cc89e34b8b1eaea014614d4e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d425344253230332d2d436c617573652d626c75652e737667)](LICENSE)

The code is distributed under the terms of [The 3-Clause BSD license](LICENSE).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity74

Established project with proven stability

 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

Every ~78 days

Recently: every ~49 days

Total

12

Last Release

1571d ago

Major Versions

1.3.1 → 2.0.02021-05-03

2.3.0 → 3.0.02022-01-23

PHP version history (4 changes)1.0.0PHP ^7.2

1.3.0PHP ^7.2|^8

2.0.0PHP ^8

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/02c41fefd80a09d9f349706dbee9f45b9cfe539509881a05af4fa8d3517a878d?d=identicon)[kodeart](/maintainers/kodeart)

---

Top Contributors

[![kodeart](https://avatars.githubusercontent.com/u/202293?v=4)](https://github.com/kodeart "kodeart (183 commits)")

---

Tags

containerdependencydependency-injectioninjectionpsr-11containerPSR-11dependencyinjectiondic

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/container

A fast and intuitive dependency injection container.

86387.8M343](/packages/league-container)[miladrahimi/phpcontainer

Dependency injection (IoC) container for PHP projects

1322.7k2](/packages/miladrahimi-phpcontainer)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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