Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifying queuing middleware #118

Closed
adriansuter opened this issue Jul 24, 2019 · 2 comments
Closed

Simplifying queuing middleware #118

adriansuter opened this issue Jul 24, 2019 · 2 comments

Comments

@adriansuter
Copy link
Contributor

adriansuter commented Jul 24, 2019

This issue is similar to slimphp/Slim#2762.

With the solution proposed in slimphp/Slim#2762 (comment), a user could for example just write

$app = AppFactory::create();
$app->addRoutingMiddleware();
$app->addErrorMiddleware(true, true, false)
    ->getDefaultErrorHandler()->forceContentType('application/json');

and only AppFactory needs to be imported. That is pretty nice for these two internal slim middlewares.

I wonder if we could simplify the other middlewares as well. I mean, for example, to add the twig middleware, a user has to write the following code.

$container = new Container();
AppFactory::setContainer($container);

$app = AppFactory::create();
// Let's add the routing middleware. Nice.
$app->addRoutingMiddleware();

// Let's add the twig middleware. Complicated.
$app->add(new TwigMiddleware(
    new Twig(__DIR__ . '/../templates', [
        'cache' => __DIR__ . '/../cache/twig',
        'auto_reload' => true,
    ]),
    $app->getContainer(),
    $app->getRouteCollector()->getRouteParser(),
    '',
    Twig::class
));

// Let's add the error middleware. Nice.
$app->addErrorMiddleware(true, true, false);

We could for example let the user add twig to the container and then he/she can simply call

$app->add(TwigMiddleware::create($app, $basePath, $twigContainerKey));

The static create() method would then get the container from the app, twig from the container, and the route parser from the app (via route collector). Of course, the method would throw exceptions whenever anything is missing (no container, twig not found, etc.).

@l0gicgate
Copy link
Member

Yes, let's do that as well. This will simplify everything for the end user tremendously.

@adriansuter
Copy link
Contributor Author

Handled in #120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants