Files
watchstate/bin/console
Abdulmohsen B. A. A. f9e40f5867 A code clean up commit.
2024-12-27 14:28:32 +03:00

71 lines
2.0 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
declare(strict_types=1);
use App\Command;
error_reporting(E_ALL);
ini_set('error_reporting', 'On');
ini_set('display_errors', 'On');
require __DIR__ . '/../pre_init.php';
/**
* Throws an exception based on an error code.
*
* @param int $number The error code.
* @param mixed $error The error message.
* @param mixed $file The file where the error occurred.
* @param int $line The line number where the error occurred.
*
* @throws ErrorException When the error code is not suppressed by error_reporting.
*/
$errorHandler = function (int $number, mixed $error, mixed $file, int $line) {
$errno = $number & error_reporting();
if (0 === $errno) {
return;
}
throw new ErrorException($error, $number, 1, $file, $line);
};
set_error_handler($errorHandler);
set_exception_handler(function (Throwable $e) {
$message = strtr('{kind}: {message} ({file}:{line}).', [
'{kind}' => $e::class,
'{line}' => $e->getLine(),
'{message}' => $e->getMessage(),
'{file}' => after($e->getFile(), ROOT_PATH),
]);
fwrite(STDERR, $message . PHP_EOL);
exit(502);
});
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
print 'Dependencies are missing please refer to https://github.com/arabcoders/watchstate/blob/master/FAQ.md';
exit(Command::FAILURE);
}
require __DIR__ . '/../vendor/autoload.php';
try {
$app = new App\Libs\Initializer()->boot();
} catch (Throwable $e) {
$message = strtr(
'CLI: Exception [{kind}] was thrown unhandled during CLI boot context. Error [{message} @ {file}:{line}].',
[
'{kind}' => $e::class,
'{line}' => $e->getLine(),
'{message}' => $e->getMessage(),
'{file}' => array_reverse(explode(ROOT_PATH, $e->getFile(), 2))[0],
]
);
fwrite(STDERR, $message . PHP_EOL);
fwrite(STDERR, $e->getTraceAsString() . PHP_EOL);
exit(503);
}
$app->console();