PHPackages                             juliangut/slim-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. juliangut/slim-controller

ActiveLibrary[Framework](/categories/framework)

juliangut/slim-controller
=========================

Slim Framework controller creator

1.5(9y ago)2539.4k7BSD-3-ClausePHPPHP &gt;=5.5

Since Mar 15Pushed 8y ago2 watchersCompare

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

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

[![PHP version](https://camo.githubusercontent.com/8c508dbfb530cc5703d088796f65f3230e83d32a68e84c73bc9e7847b12a0fa7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344352e352d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net)[![Latest Version](https://camo.githubusercontent.com/d4bae5ef7c8684ef28845c715d2002d513804df69d454abbbd51db2d17ba5aff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6a756c69616e6775742f736c696d2d636f6e74726f6c6c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/slim-controller)[![License](https://camo.githubusercontent.com/06ab6c6178b25d5f622ba986269e965ccf561378f9abd4e8c893afda608ecdc1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a756c69616e6775742f736c696d2d636f6e74726f6c6c65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/juliangut/slim-controller/blob/master/LICENSE)

[![Build status](https://camo.githubusercontent.com/26bd00916368b684bcce72194f6e34de8449a49fb235579406e5b4565a2e56c3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a756c69616e6775742f736c696d2d636f6e74726f6c6c65722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/juliangut/slim-controller)[![Style](https://camo.githubusercontent.com/a6fe319ffd5140713cff44a0951a572e39e48b7deac5a6faa6eecf4c84610c31/68747470733a2f2f7374796c6563692e696f2f7265706f732f33323039303338322f736869656c64)](https://styleci.io/repos/32090382)[![Code Quality](https://camo.githubusercontent.com/19aa11d21e3ea4c71493f0c00f470059413592439b22287297993ced3d20ce51/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a756c69616e6775742f736c696d2d636f6e74726f6c6c65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/juliangut/slim-controller)[![Code Coverage](https://camo.githubusercontent.com/1e4f01477e8baef840b5ba44f47789c076ccf222ae33672bc37bae6f6b8c671b/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a756c69616e6775742f736c696d2d636f6e74726f6c6c65722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/juliangut/slim-controller)[![Total Downloads](https://camo.githubusercontent.com/97c09b3fa66d24d724e3b1776d6349641df7496c5b710756290a623071e34749/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a756c69616e6775742f736c696d2d636f6e74726f6c6c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/slim-controller)

Slim3 controller management
===========================

[](#slim3-controller-management)

NOTICE: To anyone using this package you should consider moving to [juliangut/slim-routing](https://github.com/juliangut/slim-routing)
--------------------------------------------------------------------------------------------------------------------------------------

[](#notice-to-anyone-using-this-package-you-should-consider-moving-to-juliangutslim-routing)

Class route creation boilerplate, allows you to define your controller classes as services to be pulled out from container easily, extending from a base controller class.

I strongly suggest you don't use this library but for rapid prototyping or certain use cases. If you really want to follow SOLID principles, don't use this package and either directly inject your dependencies in the controller class, use the container to create and inject dependencies or try another container such as PHP-DI with [juliangut/slim-php-di](https://github.com/juliangut/slim-php-di)

> I cannot stress this enough, this library is meant to be used with default Slim container and for certain cases only.

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

[](#installation)

Best way to install is using [Composer](https://getcomposer.org/):

```
composer require juliangut/slim-controller

```

Then require\_once the autoload file:

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

Usage
-----

[](#usage)

```
use \Jgut\Slim\Controller\Resolver;

// Define your controllers
$controllers = [
    'MyController',
];

// Create Slim app and fetch DI Container
$app = new \Slim\App();
$container = $app->getContainer();

// Register Controllers
foreach (Resolver::resolve($controllers) as $controller => $callback) {
    $container[$controller] = $callback;
}

// Define route (\MyController has already been registered)
$app->get('hello/app', '\MyController:dispatch');

// Run app
$app->run();
```

If your controller implements `Jgut\Slim\Controller\Controller` it has the DI container automatically injected, you can access it by `getContainer` method.

If your controller extends `Jgut\Slim\Controller\Base` you can also directly access container services the same way you do on a `Closure` route callback. Simply take care to not define class attributes with the same name as services in the container. To do this container is injected in the controller and `__get` and `__isset` magic methods are defined to look into the container.

```
use Jgut\Slim\Controller\Base as BaseController;

class MyController extends BaseController
{
    public function displatch($request, $response, array $args)
    {
        // Pull Twig view service given it was defined
        return $this->view->render($response, 'dispatch.twig');
    }
}
```

You can use the resolver to define your `class` routes callback and not implement `Controller` or extend `Base` on those classes, in this case your controller won't have access to the container but it will still be a valid callback.

### Important notice

[](#important-notice)

As a general rule of thumb directly injecting container is considered a bad practice as you are actually hiding your dependencies, by fetching them from the container, instead of defining them in the class. You'll be using the container as a service locator rather than a true DIC.

### Caveat

[](#caveat)

This controller registration works only for controllers whose constructor doesn't need any parameters. In case you need a controller with paramenters in its `__construct()` method you can still benefit from `\Jgut\Slim\Controller\Controller` but you have to register it yourself.

```
use Jgut\Slim\Controller\Controller;

$container['\MyController'] = function($container) {
    $controller = new \MyController('customParameter');

    // Set container into the controller
    if ($controller instanceof Controller) {
        $controller->setContainer($container);
    }

    return $controller;
}
```

Contributing
------------

[](#contributing)

Found a bug or have a feature request? [Please open a new issue](https://github.com/juliangut/slim-controller/issues). Have a look at existing issues before

See file [CONTRIBUTING.md](https://github.com/juliangut/slim-controller/blob/master/CONTRIBUTING.md)

License
-------

[](#license)

### Release under BSD-3-Clause License.

[](#release-under-bsd-3-clause-license)

See file [LICENSE](https://github.com/juliangut/slim-controller/blob/master/LICENSE) included with the source code for a copy of the license terms

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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

Every ~59 days

Recently: every ~96 days

Total

10

Last Release

3543d ago

Major Versions

0.2 → 1.02015-08-13

0.3 → 1.52016-09-04

PHP version history (2 changes)0.1PHP &gt;=5.4

1.0PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c50421f1ab4148354dc2dd5dcaba168656b17ea913b310d112deb39a6f73ca1?d=identicon)[juliangut](/maintainers/juliangut)

---

Top Contributors

[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (32 commits)")

---

Tags

frameworkslimcontroller

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/juliangut-slim-controller/health.svg)

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

###  Alternatives

[slim/twig-view

Slim Framework 4 view helper built on top of the Twig 3 templating component

3708.0M210](/packages/slim-twig-view)[gotzmann/comet

Modern PHP framework for building blazing fast REST APIs and microservices

68816.2k1](/packages/gotzmann-comet)[akrabat/rka-slim-controller

Dynamically instantiated controller classes for Slim Framework

4827.3k1](/packages/akrabat-rka-slim-controller)[juliangut/slim-doctrine

Slim-Doctrine managers integration

153.7k](/packages/juliangut-slim-doctrine)[patricksavalle/slim-rest-api

Production-grade REST-API App-class for PHP SLIM, in production on https://zaplog.pro (https://api.zaplog.pro/v1)

101.4k](/packages/patricksavalle-slim-rest-api)

PHPackages © 2026

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