2024-05-14 02:06:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Slovocast;
|
|
|
|
|
|
|
|
use Slim\App;
|
|
|
|
use Slim\Factory\AppFactory;
|
|
|
|
use League\Config\Configuration;
|
|
|
|
use DI\Container;
|
|
|
|
use DI\ContainerBuilder;
|
2024-05-16 02:03:49 +00:00
|
|
|
use Slim\Views\Twig;
|
|
|
|
use Slim\Views\TwigMiddleware;
|
|
|
|
use Slovocast\Routes;
|
2024-05-14 02:06:01 +00:00
|
|
|
|
|
|
|
class Bootstrap
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Pulls out all the configuration schemas and configuration values.
|
|
|
|
*
|
|
|
|
* @return Configuration
|
|
|
|
*/
|
|
|
|
protected static function initConfig(): Configuration
|
|
|
|
{
|
|
|
|
$config = new Configuration();
|
|
|
|
|
|
|
|
// set all configuration details
|
|
|
|
|
|
|
|
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([
|
|
|
|
'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
|
|
|
|
{
|
2024-05-16 02:03:49 +00:00
|
|
|
Routes::init($app);
|
2024-05-14 02:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2024-05-16 02:03:49 +00:00
|
|
|
|
|
|
|
// Twig
|
2024-05-16 02:15:24 +00:00
|
|
|
$templatePath = __DIR__ . "/../templates";
|
2024-05-23 00:39:33 +00:00
|
|
|
$templateCache = false;
|
|
|
|
$twig = Twig::create($templatePath, [ 'cache' => $templateCache ]);
|
|
|
|
$app->add(TwigMiddleware::create($app));
|
2024-05-14 02:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|