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

ActiveLibrary

cee/simple-di
=============

Simple Dependency Injection Container

v1.0(8y ago)1191PHP

Since Oct 12Pushed 8y ago3 watchersCompare

[ Source](https://github.com/Travelport-Czech/SimpleDi)[ Packagist](https://packagist.org/packages/cee/simple-di)[ RSS](/packages/cee-simple-di/feed)WikiDiscussions master Synced 2mo ago

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

SimpleDi
========

[](#simpledi)

Simple Dependency Injection Container

[![Build Status](https://camo.githubusercontent.com/49142f7852dde99f307e9b1878305662a2226cb6d02778259f5cd61e5c6f0e69/68747470733a2f2f7472617669732d63692e6f72672f54726176656c706f72742d437a6563682f53696d706c6544692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Travelport-Czech/SimpleDi)

Useful for making dependency tree of a service classes. The Service class is a class which has only one instance in a application. It can be used for simple alternative to Nette Di Container. All configuration of the DI Container is in PHP language.

Basic usage
-----------

[](#basic-usage)

```
$container = new Cee\SimpleDi\Container();
$classInstance = $container->createServiceOnce('ClassName');
```

Example with interfaces as the dependencies
-------------------------------------------

[](#example-with-interfaces-as-the-dependencies)

```
interface Logger {
  public function log($message);
}
```

```
interface Mailer {
  public function send($message, $subject, $to);
}
```

The Service class providing some functionality with dependencies on previous interfaces:

```
class NotificationService {
  private $mailer;
  private $logger;

  public function __construct(Mailer $mailer, Logger $logger) {
    $this->mailer = mailer;
    $this->logger = logger;
  }

  public function notify($message, array $recipients) {
    $subject = 'Notification';
    foreach ($recipients as $recipient) {
      $this->mailer->send($message, $subject, $recipient);
    }
    $this->logger->log(...);
  }
}
```

Implementations of an interfaces:

```
class ErrorLogLogger extends Logger {
  public function log($message) {
    error_log('Error: ' . $message);
  }
}
```

```
class SendMailMailer extends Mailer {
  public function send($message, $subject, $to) {
    mail($to, $subject, $message);
  }
}
```

And finally the configuration of the Simple DI Container with created instance of the `NotificationService`:

```
$container = new Cee\SimpleDi\Container();

$container->setInterfaceImplementation(Logger::class, ErrorLogLogger::class);
$container->setInterfaceImplementation(Mailer::class, SendMailMailer::class);

$notificationService = $container->createServiceOnce(NotificationService::class);
```

Simple Di Container fill in parameters by type hint (using PHP Reflection). This is called autowiring.

Example with no type hinted parameter in constructor of the service class
-------------------------------------------------------------------------

[](#example-with-no-type-hinted-parameter-in-constructor-of-the-service-class)

```
class NotificationService {
  private $mailer;
  private $logFileName;

  public function __construct(Mailer $mailer, $logFileName) {
    $this->mailer = mailer;
    $this->logFileName = logFileName;
  }

  public function notify($message, array $recipients) {
    $subject = 'Notification';
    foreach ($recipients as $recipient) {
      $this->mailer->send($message, $subject, $recipient);
    }
    file_put_contents($logFileName, ...);
  }
}
```

Container configuration created as extending class of the Simple DI Container:

```
namespace App;

class Container extends \Cee\SimpleDi\Container {
  public function __construct($logFileName) {
    $notificationService = new \NotificationService(new SendMailMailer(), $logFileName);
    $this->addServiceInstance($notificationService);
  }
}
```

And in application we are using own Container:

```
$logFileName = 'log.txt';
$container = new App\Container($logFileName);
$notificationService = $container->createServiceOnce(NotificationService::class);
```

This example has disadvantage - `NotificationService` is created at start of the application and not on demand as other service classes created by Simple DI Container. This is useful on old code without need refactoring code. But the goal of the refactoring is create wrapper on all no type hinted parameters of the service class. In this case first refactoring step is:

```
class NotificationService {
  private $mailer;
  private $logFileName;

  public function __construct(Mailer $mailer, LogFileName $logFileName) {
  ...
```

After this, you do not need create NotificationService by own. Next step is creating of the service class Logger as is used in example with interface.

Example with already created classes
------------------------------------

[](#example-with-already-created-classes)

Typical use case is an old smell code with singletons. Or if you need successive refactoring. You have already instance of the service class before you can initiate a DI Container. You need use autowiring of this class to other.

```
class Repository {
  public function __construct(MySqlConnector $mySqlConnector) {
  ...
}
```

```
class Container extends \Cee\SimpleDi\Container {
  public function __construct(MySqlConnector $mySqlConnector) {
    $this->addServiceInstance($mySqlConnector);
  }
}
```

And it works:

```
$mySqlConnector = MySqlConnector::instance();
$container = new App\Container($mySqlConnector);
$repository = $container->createServiceOnce(Repository::class);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% 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

3136d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/21b4b377838bcee23bd65b640fc3d970caf87fcba02d41e7867dd660bbc2c35a?d=identicon)[ezop](/maintainers/ezop)

---

Top Contributors

[![buresmi7](https://avatars.githubusercontent.com/u/1267665?v=4)](https://github.com/buresmi7 "buresmi7 (30 commits)")[![MiseCZ](https://avatars.githubusercontent.com/u/16322664?v=4)](https://github.com/MiseCZ "MiseCZ (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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