64 lines
1.7 KiB
PHP
Executable File
64 lines
1.7 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Command;
|
|
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 'On');
|
|
|
|
require __DIR__ . '/../pre_init.php';
|
|
|
|
set_error_handler(function (int $number, mixed $error, mixed $file, int $line) {
|
|
$errno = $number & error_reporting();
|
|
static $errorLevels = [
|
|
E_ERROR => 'Error',
|
|
E_WARNING => 'Warning',
|
|
E_PARSE => 'Parser Error',
|
|
E_NOTICE => 'Notice',
|
|
E_CORE_ERROR => 'Core Error',
|
|
E_CORE_WARNING => 'Core Warning',
|
|
E_COMPILE_ERROR => 'Compile Error',
|
|
E_COMPILE_WARNING => 'Compile Warning',
|
|
E_USER_ERROR => 'User Error',
|
|
E_USER_WARNING => 'User Warning',
|
|
E_USER_NOTICE => 'User notice',
|
|
E_STRICT => 'Strict Notice',
|
|
E_RECOVERABLE_ERROR => 'Recoverable Error'
|
|
];
|
|
|
|
if (0 === $errno) {
|
|
return;
|
|
}
|
|
|
|
$message = sprintf('%s: %s (%s:%d).', $errorLevels[$number] ?? (string)$number, $error, $file, $line);
|
|
fwrite(STDERR, trim($message) . PHP_EOL);
|
|
|
|
exit(501);
|
|
});
|
|
|
|
set_exception_handler(function (Throwable $e) {
|
|
$message = sprintf('%s: %s (%s:%d).', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine());
|
|
fwrite(STDERR, trim($message) . PHP_EOL);
|
|
exit(502);
|
|
});
|
|
|
|
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
|
|
fwrite(STDERR, 'Dependencies are missing.' . PHP_EOL);
|
|
exit(Command::FAILURE);
|
|
}
|
|
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
|
|
try {
|
|
$app = (new App\Libs\Initializer())->boot();
|
|
} catch (Throwable $e) {
|
|
$message = sprintf('%s: %s (%s:%d).', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine());
|
|
fwrite(STDERR, trim($message) . PHP_EOL);
|
|
|
|
exit(503);
|
|
}
|
|
|
|
$app->console();
|