addDefinitions([ 'conifg' => $config, // more DI stuff ]); return $containerBuilder->build(); } /** * Tasking the instaniated Application, sets up all the routes for the * application. * * @param App $app * @return void */ protected static function establishRoutes(App $app): void { Routes::init($app); } /** * Taking an instantiated application, sets up all the middleware required * for the application to run. * * @param App $app */ protected static function establishMiddleware(App $app): void { $app->addErrorMiddleware(true, true, true); // Twig $templatePath = __DIR__ . "/../templates"; $templateCache = false; $twig = Twig::create($templatePath, [ 'cache' => $templateCache ]); // Add the global variables $twig->getEnvironment()->addGlobal('site_name', "Slovocast"); $twig->getEnvironment()->addGlobal('site_description', "A no-bullshit podcast hosting service"); $app->add(TwigMiddleware::create($app, $twig)); } /** * Instantiates the application. * * @return App */ public static function init(): App { $container = self::initContainer(); $app = AppFactory::createFromContainer($container); self::establishMiddleware($app); self::establishRoutes($app); return $app; } }