<?php

declare(strict_types=1);

use Jnjxp\App\AppInterface as App;

// Delegate static file requests back to the PHP built-in webserver
if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) {
    return false;
}

chdir(dirname(__DIR__));
require 'vendor/autoload.php';

// SET Default Lang
// NOTE: Don't forget to compile locale's on the server!
setlocale(LC_ALL, 'en_US.UTF-8');
bindtextdomain('messages', 'data/locale');
bind_textdomain_codeset('messages', 'UTF-8');
textdomain('messages');

(function () {
    $container = require 'config/container.php';

    if ($container->get('DEBUG')) {
        require 'config/debug.php';
    } else {
        require 'config/handle_errors.php';
    }

    $pipe = (require 'config/pipe.php')($container);

    $app = $container->get(App::class);
    $app->run($pipe);
})();
