Skip to content

@jiripudil jiripudil released this Nov 30, 2017 · 1 commit to master since this release

We developers are lazy, and so should be our applications. ApplicationConfigurators can now register not only callbacks, but also service types directly. This means that where you formerly wrote

namespace My\App;
class Configurator implements ApplicationConfigurator
{
    private $controller;
    public function __construct(Controller $controller)
    {
        $this->controller = $controller;
    }

    public function configureApplication(Slim\App $app)
    {
        $app->get('/route', $this->controller);
    }
}

you can now write

namespace My\App;
class Configurator implements ApplicationConfigurator
{
    public function configureApplication(Slim\App $app)
    {
        $app->get('/route', Controller::class);
    }
}

The Controller is automatically fetched from the DI container as long as it is registered as a service. This way you can optimize your applications because dependencies are not instantiated unnecessarily.

If you don't use invokable classes and want to point to a specific method of the class, you can write

namespace My\App;
class Configurator implements ApplicationConfigurator
{
    public function configureApplication(Slim\App $app)
    {
        $app->get('/route', Controller::class . ':method');
    }
}
Assets 2
You can’t perform that action at this time.