PHPackages                             ifyazilim/slim-bridge-with-controller - 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. ifyazilim/slim-bridge-with-controller

ActiveLibrary[Framework](/categories/framework)

ifyazilim/slim-bridge-with-controller
=====================================

PHP-DI integration in Slim with Controller

3.4.0(2y ago)028MITPHPPHP ^7.1 || ^8.0

Since Mar 5Pushed 2y agoCompare

[ Source](https://github.com/ifyazilim/Slim-Bridge-With-Controller)[ Packagist](https://packagist.org/packages/ifyazilim/slim-bridge-with-controller)[ RSS](/packages/ifyazilim-slim-bridge-with-controller/feed)WikiDiscussions master Synced 1mo ago

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

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

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

This package is dron-in-replacement of PHP-DI/Slim-Bridge with Controller

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

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

This package configures Slim 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 (ServerRequestInterface $request, RequestHandlerInterface $handler) {
    $request = $request->withAttribute('name', 'Bob');
    $response = $handler->handle($request);
    return $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

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

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

799d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f91277d3343bdd0656c9fe2251e7e59586a22496f4065fbe4bd6e85341618b8?d=identicon)[irfanevrens](/maintainers/irfanevrens)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (65 commits)")[![fritsvt](https://avatars.githubusercontent.com/u/26067146?v=4)](https://github.com/fritsvt "fritsvt (4 commits)")[![arokettu](https://avatars.githubusercontent.com/u/963485?v=4)](https://github.com/arokettu "arokettu (4 commits)")[![Rarst](https://avatars.githubusercontent.com/u/737584?v=4)](https://github.com/Rarst "Rarst (3 commits)")[![juherr](https://avatars.githubusercontent.com/u/254697?v=4)](https://github.com/juherr "juherr (2 commits)")[![irfanevrens](https://avatars.githubusercontent.com/u/166640?v=4)](https://github.com/irfanevrens "irfanevrens (1 commits)")[![jackwilsdon](https://avatars.githubusercontent.com/u/1843197?v=4)](https://github.com/jackwilsdon "jackwilsdon (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)")[![benyafai](https://avatars.githubusercontent.com/u/1727812?v=4)](https://github.com/benyafai "benyafai (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)")[![iGroovyboy](https://avatars.githubusercontent.com/u/32447496?v=4)](https://github.com/iGroovyboy "iGroovyboy (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ifyazilim-slim-bridge-with-controller/health.svg)

```
[![Health](https://phpackages.com/badges/ifyazilim-slim-bridge-with-controller/health.svg)](https://phpackages.com/packages/ifyazilim-slim-bridge-with-controller)
```

###  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)
