add middleware and use DI-bridge for instantiating app and add routes
This commit is contained in:
parent
859cde777a
commit
2bc3dfc3ec
1 changed files with 14 additions and 3 deletions
|
|
@ -1,19 +1,30 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Slim\Factory\AppFactory;
|
use DI\Bridge\Slim\Bridge;
|
||||||
|
use Slim\Csrf\Guard as CsrfMiddleware;
|
||||||
use Slim\Views\Twig;
|
use Slim\Views\Twig;
|
||||||
use Slim\Views\TwigMiddleware;
|
use Slim\Views\TwigMiddleware;
|
||||||
use FreightQuote\User\UserController;
|
use FreightQuote\User\UserController;
|
||||||
|
use FreightQuote\MiddleWare\AuthMiddleware;
|
||||||
|
use FreightQuote\MiddleWare\CsrfToTwigMiddleware;
|
||||||
|
|
||||||
$container = require __DIR__.'/container.php';
|
$container = require __DIR__.'/container.php';
|
||||||
|
$app = Bridge::create($container);
|
||||||
$app = AppFactory::createFromContainer($container);
|
|
||||||
|
|
||||||
$twig = Twig::create(__DIR__ . '/../templates', ['cache' => false]);
|
$twig = Twig::create(__DIR__ . '/../templates', ['cache' => false]);
|
||||||
|
|
||||||
|
$responseFactory = $app->getResponseFactory();
|
||||||
|
$csrf = new CsrfMiddleware($responseFactory);
|
||||||
|
$csrfTwig = new CsrfToTwigMiddleware($twig);
|
||||||
|
$auth = new AuthMiddleware();
|
||||||
|
$app->add($csrf);
|
||||||
|
$app->add($csrfTwig);
|
||||||
$app->add(TwigMiddleware::create($app, $twig));
|
$app->add(TwigMiddleware::create($app, $twig));
|
||||||
$app->addErrorMiddleware(true, false, false);
|
$app->addErrorMiddleware(true, false, false);
|
||||||
|
|
||||||
$app->get('/', [UserController::class, 'home']);
|
$app->get('/', [UserController::class, 'home']);
|
||||||
|
$app->get('/login', [UserController::class, 'login']);
|
||||||
|
$app->post('/login', [UserController::class, 'doLogin']);
|
||||||
|
$app->get('/dashboard', [UserController::class, 'dashboard'])->add($auth);
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue