PHPackages                             jenssegers/lean - 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. jenssegers/lean

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

jenssegers/lean
===============

Use the league/container with auto-wiring support as the core container in Slim 3

v1.0.2(7y ago)313.4k5[3 issues](https://github.com/jenssegers/lean/issues)MITPHPPHP &gt;=7.0

Since Nov 22Pushed 7y ago3 watchersCompare

[ Source](https://github.com/jenssegers/lean)[ Packagist](https://packagist.org/packages/jenssegers/lean)[ Docs](https://github.com/jenssegers/lean)[ RSS](/packages/jenssegers-lean/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (11)Used By (0)

Lean
====

[](#lean)

[![Latest Stable Version](https://camo.githubusercontent.com/ae9f36184740f2193064190b578ae62d8038bf6caeeeed449d978046432b2078/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a656e737365676572732f6c65616e2e737667)](https://packagist.org/packages/jenssegers/lean) [![Build Status](https://camo.githubusercontent.com/a8b0732f68d68098bcdc8a2160f14aade8f38cf2be6d83765f01bd61c56a667f/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f6a656e737365676572732f6c65616e2e737667)](https://travis-ci.org/jenssegers/lean) [![Coverage Status](https://camo.githubusercontent.com/08cea9fd08de39253f5e419a67c576c7eac19a2a3f013b4c7cddc8f9b47f0628/687474703a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a656e737365676572732f6c65616e2e737667)](https://coveralls.io/r/jenssegers/lean)

Lean allows you to use the [PHP League's Container](https://github.com/thephpleague/container) package with auto-wiring support as the core container in [Slim 3](https://github.com/slimphp/Slim).

Install
-------

[](#install)

Via Composer

```
$ composer require jenssegers/lean
```

Usage
-----

[](#usage)

The easiest way to start using Lean is simply creating a `Jenssegers\Lean\App` instance:

```
require 'vendor/autoload.php';

$app = new \Jenssegers\Lean\App();

$app->get('/hello/{name}', function (Request $request, Response $response, string $name) {
    return $response->write('Hello, ' . $name);
});

$app->run();
```

Behind the scenes, a Slim application is bootstrapped by adding all of the required Slim components to League's container.

Service Providers
-----------------

[](#service-providers)

Service providers give the benefit of organising your container definitions along with an increase in performance for larger applications as definitions registered within a service provider are lazily registered at the point where a service is retrieved.

To build a service provider it is as simple as extending the base service provider and defining what you would like to register.

```
use League\Container\ServiceProvider\AbstractServiceProvider;

class SomeServiceProvider extends AbstractServiceProvider
{
    /**
     * The provided array is a way to let the container
     * know that a service is provided by this service
     * provider. Every service that is registered via
     * this service provider must have an alias added
     * to this array or it will be ignored.
     */
    protected $provides = [
        SomeInterface::class,
    ];

    /**
     * This is where the magic happens, within the method you can
     * access the container and register or retrieve anything
     * that you need to, but remember, every alias registered
     * within this method must be declared in the `$provides` array.
     */
    public function register()
    {
        $this->getContainer()
            ->add(SomeInterface::class, SomeImplementation::class);
    }
}
```

To register this service provider with the container simply pass an instance of your provider or a fully qualified class name to the League\\Container\\Container::addServiceProvider method.

```
$app = new \Jenssegers\Lean\App();
$app->getContainer()->addServiceProvider(\Acme\ServiceProvider\SomeServiceProvider::class);
```

Read more about service providers [here](https://container.thephpleague.com/3.x/service-providers/).

Settings
--------

[](#settings)

You can access Slim's internal configuration through the `settings` key on the container:

```
$app = new \Jenssegers\Lean\App();

$app->getContainer()->get('settings')['displayErrorDetails'] = true;
```

Alternatively, an alias is registered that allows a bit more fluent way of working with settings:

```
$app = new \Jenssegers\Lean\App();

$app->getContainer()->get(\Slim\Settings::class)->set('displayErrorDetails', true);
```

Read more about the available configuration options [here](https://www.slimframework.com/docs/v3/objects/application.html#slim-default-settings).

Route arguments
===============

[](#route-arguments)

By default, Lean will use method injection to pass arguments to your routes. This allows you to type-hint dependencies on method level (similar to the Laravel framework).

Route arguments will be passed as individual arguments to your method:

```
$app->get('/books/{id}', function (Request $request, Response $response, string $id) {
    ...
});
```

They are also accessible through the `getAttribute` method.

```
$app->get('/books/{id}', function (Request $request, Response $response) {
    $id = $request->getAttribute('id');
    ....
});
```

If you want to disable this behaviour and use the default Slim way of route arguments, you can disable this feature be setting `methodInjection` to `false`:

```
$app->getContainer()->get(\Slim\Settings::class)->set('methodInjection', false);
```

Read more about routes [here](http://www.slimframework.com/docs/v3/objects/router.html).

Error Handlers
--------------

[](#error-handlers)

By default, Lean uses Slim's error handlers. There are different ways to implement an error handler for Slim, read more about them [here](https://www.slimframework.com/docs/v3/handlers/error.html).

Typically you would create a custom error handler class that looks like this:

```
class CustomErrorHandler
{
    public function __invoke(ServerRequestInterface $request, Response $response, Throwable $exception)
    {
        return $response->withJson([
            'error' => 'Something went wrong',
        ], 500);
    }
}
```

Then you overwrite the default handler by adding it to the container:

```
$app = new Jenssegers\Lean\App();

$app->getContainer()->share('errorHandler', function () {
    return new CustomErrorHandler();
});
```

Ideally, you would put this code inside a service provider. Read more about service providers above.

Testing
-------

[](#testing)

```
$ php ./vendor/bin/phpunit
```

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 95.7% 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 ~127 days

Recently: every ~50 days

Total

10

Last Release

2681d ago

Major Versions

v0.3.0 → v1.0.0-beta2018-08-13

PHP version history (4 changes)v0.1.0PHP &gt;=5.5.0

v0.3.0PHP &gt;=5.5

v1.0.0-betaPHP &gt;=5.6

v1.0.1PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/91980fbd02c3e65e0b2ec1c65e4ca0131f1bbc3929a0a11a7f4f12db5f2036e3?d=identicon)[jenssegers](/maintainers/jenssegers)

---

Top Contributors

[![jenssegers](https://avatars.githubusercontent.com/u/194377?v=4)](https://github.com/jenssegers "jenssegers (44 commits)")[![wouterds](https://avatars.githubusercontent.com/u/1210628?v=4)](https://github.com/wouterds "wouterds (2 commits)")

---

Tags

container-interopdependency-injectionleaguephp-leagueslimcontainerleagueslim

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jenssegers-lean/health.svg)

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

###  Alternatives

[psr/container

Common Container Interface (PHP FIG PSR-11)

10.0k1.0B3.7k](/packages/psr-container)[league/container

A fast and intuitive dependency injection container.

86787.8M343](/packages/league-container)[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[league/tactician-container

Tactician integration for any container implementing PSR-11

7710.1M23](/packages/league-tactician-container)[juliangut/slim-php-di

Slim Framework PHP-DI container integration

1729.9k2](/packages/juliangut-slim-php-di)

PHPackages © 2026

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