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

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

trifs/di
========

A simple dependency injection container

v1.0.0(11y ago)124.3k1MITPHPPHP &gt;=5.4

Since Jul 30Pushed 11y ago1 watchersCompare

[ Source](https://github.com/3fs/php-di)[ Packagist](https://packagist.org/packages/trifs/di)[ Docs](https://github.com/3fs/php-di)[ RSS](/packages/trifs-di/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (2)Used By (1)

trifs/DI
========

[](#trifsdi)

trifs/DI is a simple Dependency Injection Container for PHP, based on awesome [Pimple](http://pimple.sensiolabs.org/) internals. It is, however, behaving as an object, not as an array. It also provides less features, namely protecting parameters, modifying services after creation and fetching the service creation function.

[![Build Status](https://camo.githubusercontent.com/9148c20de1b7bfbc5278486a3270deb358b9c7718180fd6c5a4cfe6597fbcc23/68747470733a2f2f7472617669732d63692e6f72672f3366732f7068702d64692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/3fs/php-di)

Installation
------------

[](#installation)

To include trifs/DI in your project, add it to your `composer.json`:

```
{
    "require": {
        "trifs/di": "~1.0"
    }
}
```

Usage
-----

[](#usage)

Creating a container is as simple as instantiating it:

```
use trifs\DI;

$container = new Container();
```

As many other dependency injection containers, trifs\\DI is able to manage two different kind of data; services and parameters.

### Defining parameters

[](#defining-parameters)

```
$container->cookie_name = 'SESSION_ID';
$container->session_storage_class = 'SessionStorage';
```

### Defining services

[](#defining-services)

A service is an object that does something as part of a larger system, for example: database connection, session handler, etc.

Services are defined by anonymous functions that return an instance of an object:

```
$container->session_storage = function (Container $container) {
    return new $container->session_storage_class($container->cookie_name);
};

$container->session = function (Container $container) {
    return new Session($c['session_storage']);
};
```

Notice that the anonymous function has access to the current container instance, allowing references to other services or parameters.

As objects are only created when you get them, the order of the definitions does not matter, and there is no performance penalty.

Using the defined services is also very easy:

```
// get the session object
$session = $container->session;

// the above call is roughly equivalent to the following code:
// $storage = new SessionStorage('SESSION_ID');
// $session = new Session($storage);
```

### Extending a container

[](#extending-a-container)

If you use the same libraries over and over, you might want to reuse some services from one project to the other; package your services into a provider by implementing `trifs\DI\ServiceProviderInterface`:

```
use trifs\DI\Container;
use trifs\DI\ServiceProviderInterface;

class FooProvider implements ServiceProviderInterface
{
    public function register(Container $container)
    {
        // register services and parameters
    }
}
```

And to register it:

```
$container->register(new FooProvider());
```

### Defining factory services

[](#defining-factory-services)

By default, each time you get a service, trifs\\DI returns the same instance of it. If you want a different instance to be returned for all calls, wrap your anonymous function with the `factory()` method:

```
$container->session = $container->factory(function (Container $container) {
    return new Session($container->session_storage);
});
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4310d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8b2d345243ba7b2f60907bbad7f52d9e02f8938c93c476a15033e03333d4e39?d=identicon)[davidkuridza](/maintainers/davidkuridza)

---

Top Contributors

[![davidkuridza](https://avatars.githubusercontent.com/u/953796?v=4)](https://github.com/davidkuridza "davidkuridza (1 commits)")

---

Tags

containerdependency-injectiondi

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

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

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

356968.3k58](/packages/aura-di)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3611.7M3](/packages/mrclay-props-dic)[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)
