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

ActiveLibrary[Framework](/categories/framework)

phpatom/di
==========

An expressive and flexible dependency injection container for PHP

v0.3.1(5y ago)048MITPHPPHP ^7.4|8.\*

Since Aug 21Pushed 2y agoCompare

[ Source](https://github.com/dani-gouken/di)[ Packagist](https://packagist.org/packages/phpatom/di)[ RSS](/packages/phpatom-di/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

### Atom DI

[](#atom-di)

![Status](https://camo.githubusercontent.com/263f3694f42afc27e06a1ff829cd63884893b55624e13a16893dd0a3ba772b94/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374617475732d6163746976652d737563636573732e737667)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](/LICENSE)[![Build Status](https://camo.githubusercontent.com/70c673bc43c0beb7a87f01ab045241f9acd0d8b592f9d14f7786590455d717e8/68747470733a2f2f7472617669732d63692e6f72672f70687061746f6d2f44492e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpatom/DI)[![codecov](https://camo.githubusercontent.com/d91d71b6f327418801d202407c193f9c027a6e71ef30869c57c5190cf584da32/68747470733a2f2f636f6465636f762e696f2f67682f70687061746f6d2f44492f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/phpatom/DI)

---

 An expressive and flexible dependency injection container for PHP

📝 Table of Contents
-------------------

[](#-table-of-contents)

- [Prerequisites](#prerequisites)
- [Installing](#installing)
- [Testing](#testing)
- [Coding Style](#coding_style)
- [Getting Started](#getting_started)
- [Usage](#usage)
- [Contributing](#contributing)
- [Authors](#authors)

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

[](#prerequisites-)

- PHP 8.2 +
- Composer

Installing
-------------------------------------------------

[](#installing-)

The recommended way to install is via Composer:

```
composer require phpatom/di

```

Testing Installing
------------------------------------------------------

[](#testing-installing-)

```
composer test

```

### Coding style

[](#coding-style-)

```
./vendor/bin/phpcs

```

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

[](#getting-started-)

### Instantiate the container

[](#instantiate-the-container)

```
use Atom\DI\Container;

$container = new Container();
```

### Basic usage

[](#basic-usage)

```
use Atom\DI\Definition;
use Atom\DI\Definition;

require_once "vendor/autoload.php";

class User
{
    public function __construct(public readonly string $name)
    {
    }
}

class UserRepository
{
    public function __construct(private User $user)
    {

    }
    public function getUser(): User
    {
        return $this->user;
    }

}

class AuthService
{
    public function __construct(private UserRepository $userRepository)
    {
    }

    public function getUser(): User
    {
        return $this->userRepository->getUser();
    }

}

class Controller
{

    public function index(AuthService $authService): void
    {
        echo sprintf("Hello %s\n", $authService->getUser()->name);
    }

}

use Atom\DI\Container;

$container = new Container();

$definition = $container->bind(AuthService::class)
    ->toNewInstance()
    ->withClass(
        UserRepository::class,
        Definition::newInstanceOf(UserRepository::class)
            ->withParameter('user', new User(name: "daniel"))
    );

// output: hello daniel
$container->callMethod(Controller::class, 'index');
```

### Factories

[](#factories)

```
use Atom\DI\Container;
use Atom\DI\Definition;

class UserFactory
{
    public function __construct(
        private int $previousId = 0
    ) {
    }

    public function makeUser(): User
    {
        $user = new User(
            sprintf("User #%d", $this->previousId),
            id: $this->previousId,
        );
        $this->previousId++;
        return $user;

    }
}

/**
 * the definition is either a prototype or a singleton, singleton is the default
 */
$container->bind(UserFactory::class)->singleton();
// output: hello daniel
$container->bind(
    User::class,
    Definition::callTo("makeUser")
        ->method()
        ->on(Definition::get(UserFactory::class))
)
    ->prototype(); // without this, the instance will be cached
// output: int(0)
var_dump($container->get(User::class)->id);
// output: int(1)
var_dump($container->get(User::class)->id);
```

### Values

[](#values)

```
use Atom\DI\Container;
use Atom\DI\Definition;

$container = new Container();

$container->bind('foo', "bar");
//or
$container->bind('daniel')
    ->toValue(new User(name: "Nghokeng Daniel", id: 28));

//output: bar
echo $container->get('foo'), "\n";
```

### Array access

[](#array-access)

```
use Atom\DI\Container;
use Atom\DI\Definition;

$container = new Container();
function makeDaniel()
{
    return new User("daniel", 28);
}

$container['foo'] = "bar";
$container['daniel'] = Definition::callTo("makeDaniel")
    ->function();

//output: bar
echo $container['foo'], "\n";
//output: daniel
echo $container['daniel']->name, "\n";
```

Contributing
-----------------------------------------------------

[](#contributing-)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

✍️ Author
---------------------------------------------

[](#️-author-)

- [@dani-gouken](https://github.com/dani-gouken) - Idea &amp; Initial work

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81% 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 ~74 days

Total

4

Last Release

1870d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/60be0245dc2ad769d369accc8b2c8a4a6c68e0675c393562e825efb0b73d5c4d?d=identicon)[Nghokeng Daniel](/maintainers/Nghokeng%20Daniel)

---

Top Contributors

[![dani-gouken](https://avatars.githubusercontent.com/u/54918247?v=4)](https://github.com/dani-gouken "dani-gouken (17 commits)")[![nghokeng-ycode](https://avatars.githubusercontent.com/u/132259660?v=4)](https://github.com/nghokeng-ycode "nghokeng-ycode (4 commits)")

---

Tags

containerPSR-11frameworkdependency-injectionatomdiiocinversion of controldependency injection container

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[joomla/di

Joomla DI Package

15391.2k11](/packages/joomla-di)[mouf/mouf

The Mouf PHP framework: an open-source PHP framework providing an easy way to download, install, use and reuse components, with a graphical user interface.

55146.0k17](/packages/mouf-mouf)[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)
