This repository has been archived on 2025-05-19. You can view files and clone it, but cannot push or open issues or pull requests.
Files
old/src/app/Core/Bootstrapper.php

76 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace App\Core;
use App\Extensions\TwigFunctions;
use Flight;
use Twig\Environment;
use Twig\Extension\DebugExtension;
use Twig\Loader\FilesystemLoader;
/**
* Сборщик приложения
*/
final class Bootstrapper
{
/**
* Загружает конфигурацию приложения в контейнер
*
* @return void
*/
public static function bootSettings(): void
{
$config = require_once config_path('app.php');
foreach ($config as $key => $value) {
Flight::set($key, $value);
}
Flight::set('config', $config);
}
public static function bootCore(): void
{
$loader = new IniFile();
$loader->load();
Flight::set('ini', $loader);
}
/**
* Загружает шаблонизатор и его расширения
*
* @return void
*/
public static function bootTwig(): void
{
$twigCfg = [
'cache' => config('twig.cache'),
'debug' => config('twig.debug'),
];
$closure = static function ($twig) {
/** @var Environment $twig */
Flight::set('twig', $twig);
$twig->addExtension(new TwigFunctions());
$twig->addExtension(new DebugExtension());
};
$loader = new FilesystemLoader(config('flight.views.path'));
Flight::register('view', Environment::class, [$loader, $twigCfg], $closure);
}
/**
* Загружает маршруты
*
* @return void
*/
public static function bootRoutes(): void
{
$routes = require_once config_path('routes.php');
foreach ($routes as $route => $handler) {
Flight::route($route, $handler);
}
}
}