addSchema('site', SiteInformationSchema::getSchema()); $config->addSchema('database', DatabaseConnectionSchema::getSchema()); $config->merge([ 'site' => [ 'name' => "Slovocast", 'description' => "A no-bullshit podcast hosting platform.", 'tags' => [ 'podcast', 'hosting', 'indie', 'independent', 'easy' ] ], ]); return $config; } /** * Set up the Container with all of its definitions, as well as * initialization of configuration. * * @return Container */ protected static function initContainer(): Container { $containerBuilder = new ContainerBuilder(); $config = self::initConfig(); $containerBuilder->addDefinitions([ 'config' => $config, // more DI stuff 'flash' => function () { $messages = []; return new \Slim\Flash\Messages($messages); } ]); 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 { /** * @var Configuration */ $config = $app->getContainer()->get('config'); $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', $config->get('site.name')); $twig->getEnvironment() ->addGlobal('site_description', $config->get('site.description')); $app->add(TwigMiddleware::create($app, $twig)); // Flash Messages $app->add(function ($req, $next) { if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); } $this->get('flash')->__construct($_SESSION); return $next->handle($req); }); } /** * 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; } }