2024-07-18 01:32:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Slovocast;
|
|
|
|
|
|
|
|
use League\Config\Configuration;
|
2024-12-09 14:29:03 +00:00
|
|
|
use Odan\Session\Middleware\SessionStartMiddleware;
|
2024-07-18 01:32:25 +00:00
|
|
|
use Odan\Session\SessionInterface;
|
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
use Slim\App;
|
|
|
|
use Slim\Views\Twig;
|
|
|
|
use Slim\Views\TwigMiddleware;
|
|
|
|
use Twig\Error\LoaderError;
|
|
|
|
|
|
|
|
class Middlewares
|
|
|
|
{
|
|
|
|
/**
|
2024-12-30 21:08:20 +00:00
|
|
|
* Set up all the application middleware. This is where the application
|
|
|
|
* should determine the environment the code is running in as well.
|
|
|
|
*
|
2024-11-26 01:45:16 +00:00
|
|
|
* @param App $app The Slim application
|
2024-11-26 03:08:28 +00:00
|
|
|
* @return void
|
2024-07-18 01:32:25 +00:00
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws LoaderError
|
|
|
|
*/
|
|
|
|
public static function setup(App $app): void
|
|
|
|
{
|
|
|
|
/** @var ContainerInterface $container */
|
|
|
|
$container = $app->getContainer();
|
|
|
|
|
2024-11-29 19:50:27 +00:00
|
|
|
/** @var Configuration $config */
|
2024-07-18 01:32:25 +00:00
|
|
|
$config = $container->get('config');
|
|
|
|
|
2024-11-25 02:22:49 +00:00
|
|
|
/**
|
|
|
|
* Global session start
|
|
|
|
*/
|
2024-12-09 14:29:03 +00:00
|
|
|
$app->add(SessionStartMiddleware::class);
|
2024-11-25 02:22:49 +00:00
|
|
|
|
2024-07-18 01:32:25 +00:00
|
|
|
// Twig
|
|
|
|
$templateCache = false;
|
2024-12-03 03:11:12 +00:00
|
|
|
$twig = Twig::create(APP_TEMPLATES_DIR, [
|
2024-11-25 03:22:57 +00:00
|
|
|
'cache' => $templateCache,
|
|
|
|
'debug' => true,
|
|
|
|
]);
|
2024-07-18 01:32:25 +00:00
|
|
|
|
|
|
|
// Add the global variables
|
2024-12-30 21:08:20 +00:00
|
|
|
$twig->getEnvironment()
|
|
|
|
->addGlobal('site_name', $config->get('site.name'));
|
|
|
|
$twig->getEnvironment()
|
|
|
|
->addGlobal('site_description', $config->get('site.description'));
|
2024-11-25 03:10:36 +00:00
|
|
|
|
2024-12-09 02:59:39 +00:00
|
|
|
/** @var SessionInterface $session */
|
2024-11-26 01:45:16 +00:00
|
|
|
$session = $container->get(SessionInterface::class);
|
|
|
|
$twig->getEnvironment()->addGlobal('session', $session);
|
2024-11-25 03:10:36 +00:00
|
|
|
|
2024-07-18 01:32:25 +00:00
|
|
|
$app->add(TwigMiddleware::create($app, $twig));
|
|
|
|
|
|
|
|
// Add the error handling middleware
|
2024-12-03 03:11:12 +00:00
|
|
|
$app->addErrorMiddleware(true, true, true);
|
2024-07-18 01:32:25 +00:00
|
|
|
}
|
|
|
|
}
|