PHPackages                             edgetelemetrics/php-di-slim3-bridge - 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. edgetelemetrics/php-di-slim3-bridge

ActiveLibrary[Framework](/categories/framework)

edgetelemetrics/php-di-slim3-bridge
===================================

PHP-DI integration in Slim 3

3.2.0(4y ago)0205—0%MITPHPPHP ^7.1 || ^8.0

Since Dec 28Pushed 1y agoCompare

[ Source](https://github.com/lucasnetau/PHPDI-Slim3-Bridge)[ Packagist](https://packagist.org/packages/edgetelemetrics/php-di-slim3-bridge)[ RSS](/packages/edgetelemetrics-php-di-slim3-bridge/feed)WikiDiscussions main Synced 1mo ago

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

PHP-DI integration with Slim
============================

[](#php-di-integration-with-slim)

This package configures Slim 3 to work with the [PHP-DI container](http://php-di.org/).

[![Build Status](https://camo.githubusercontent.com/59865324e9f001b75368b66e74c36fa25edee9d42eb865784999e9b750b9531f/68747470733a2f2f7472617669732d63692e6f72672f5048502d44492f536c696d2d4272696467652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/PHP-DI/Slim-Bridge)[![](https://camo.githubusercontent.com/766fa1cc0aa13e27d5dddbdd33d996876968595772c7ea5e6528543e34f5231e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068702d64692f736c696d2d6272696467652e737667)](https://packagist.org/packages/php-di/slim-bridge)

The full documentation is here: ****

Why?
----

[](#why)

### PHP-DI as a container

[](#php-di-as-a-container)

The most obvious difference with the default Slim installation is that you will be using PHP-DI as the container, which has the following benefits:

- [autowiring](http://php-di.org/doc/autowiring.html)
- powerful [configuration format](http://php-di.org/doc/php-definitions.html)
- support for [modular systems](http://php-di.org/doc/definition-overriding.html)
- ...

If you want to learn more about all that PHP-DI can offer [have a look at its introduction](http://php-di.org/).

### Controllers as services

[](#controllers-as-services)

While your controllers can be simple closures, you can also **write them as classes and have PHP-DI instantiate them only when they are called**:

```
class UserController
{
    private $userRepository;

    public function __construct(UserRepository $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    public function delete($request, $response)
    {
        $this->userRepository->remove($request->getAttribute('id'));

        $response->getBody()->write('User deleted');
        return $response;
    }
}

$app->delete('/user/{id}', ['UserController', 'delete']);
```

Dependencies can then be injected in your controller using [autowiring, PHP-DI config files or even annotations](http://php-di.org/doc/definition.html).

### Controller parameters

[](#controller-parameters)

By default, Slim controllers have a strict signature: `$request, $response, $args`. The PHP-DI bridge offers a more flexible and developer friendly alternative.

Controller parameters can be any of these things:

- the request or response (parameters must be named `$request` or `$response`)
- route placeholders
- request attributes
- services (injected by type-hint)

You can mix all these types of parameters together too. They will be matched by priority in the order of the list above.

#### Request or response injection

[](#request-or-response-injection)

You can inject the request or response in the controller parameters by name:

```
$app->get('/', function (ResponseInterface $response, ServerRequestInterface $request) {
    // ...
});
```

As you can see, the order of the parameters doesn't matter. That allows to skip injecting the `$request` if it's not needed for example.

#### Route placeholder injection

[](#route-placeholder-injection)

```
$app->get('/hello/{name}', function ($name, ResponseInterface $response) {
    $response->getBody()->write('Hello ' . $name);
    return $response;
});
```

As you can see above, the route's URL contains a `name` placeholder. By simply adding a parameter **with the same name** to the controller, PHP-DI will directly inject it.

#### Request attribute injection

[](#request-attribute-injection)

```
$app->add(function ($request, $response, $next) {
    $request = $request->withAttribute('name', 'Bob');
    return $next($request, $response);
});

$app->get('/', function ($name, ResponseInterface $response) {
    $response->getBody()->write('Hello ' . $name);
    return $response;
});
```

As you can see above, a middleware sets a `name` attribute. By simply adding a parameter **with the same name** to the controller, PHP-DI will directly inject it.

#### Service injection

[](#service-injection)

To inject services into your controllers, you can write them as classes. But if you want to write a micro-application using closures, you don't have to give up dependency injection either.

You can inject services by type-hinting them:

```
$app->get('/', function (ResponseInterface $response, Twig $twig) {
    return $twig->render($response, 'home.twig');
});
```

> Note: you can only inject services that you can type-hint and that PHP-DI can provide. Type-hint injection is simple, it simply injects the result of `$container->get(/* the type-hinted class */)`.

Documentation
-------------

[](#documentation)

The documentation can be read here: ****

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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 ~133 days

Recently: every ~196 days

Total

17

Last Release

1653d ago

Major Versions

0.2.1 → 1.0.02016-03-08

1.1.2 → 2.0.02018-02-24

2.0.0 → 3.0.02019-09-08

PHP version history (5 changes)0.1.0PHP ~5.6|~7.0

1.0.2PHP ~5.5|~7.0

2.0.0PHP ~7.0

3.0.0PHP ~7.1

3.1.0PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/83ab22a74b2d8a4cbb5b9774d999c409cc355d1d0d948f5f9ee4d1fe0299de62?d=identicon)[lucasnetau](/maintainers/lucasnetau)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (49 commits)")[![lucasnetau](https://avatars.githubusercontent.com/u/9331242?v=4)](https://github.com/lucasnetau "lucasnetau (2 commits)")[![jackwilsdon](https://avatars.githubusercontent.com/u/1843197?v=4)](https://github.com/jackwilsdon "jackwilsdon (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![danmichaelo](https://avatars.githubusercontent.com/u/434495?v=4)](https://github.com/danmichaelo "danmichaelo (1 commits)")[![tflight](https://avatars.githubusercontent.com/u/4959691?v=4)](https://github.com/tflight "tflight (1 commits)")[![vonalbert](https://avatars.githubusercontent.com/u/6561324?v=4)](https://github.com/vonalbert "vonalbert (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/edgetelemetrics-php-di-slim3-bridge/health.svg)

```
[![Health](https://phpackages.com/badges/edgetelemetrics-php-di-slim3-bridge/health.svg)](https://phpackages.com/packages/edgetelemetrics-php-di-slim3-bridge)
```

###  Alternatives

[php-di/slim-bridge

PHP-DI integration in Slim

1786.7M98](/packages/php-di-slim-bridge)[slim/slim-skeleton

A Slim Framework skeleton application for rapid development

1.6k458.7k6](/packages/slim-slim-skeleton)[brandembassy/slim-nette-extension

19190.2k](/packages/brandembassy-slim-nette-extension)[php-di/silex-bridge

PHP-DI integration in Silex

2465.4k1](/packages/php-di-silex-bridge)[vesp/core

Vesp core library to make backend simple

243.8k5](/packages/vesp-core)[forme/framework

An MVC framework for WordPress.

175.0k3](/packages/forme-framework)

PHPackages © 2026

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