php-kilo/kilo
Timothy Warren dd4b707d12
All checks were successful
timw4mail/php-kilo/pipeline/head This commit looks good
Do autoloading without composer
2023-10-09 13:15:37 +00:00

70 lines
1.5 KiB
PHP
Executable File

#!/usr/bin/env php
<?php declare(strict_types=1);
namespace Aviat\Kilo;
require_once __DIR__ . '/src/constants.php';
require_once __DIR__ . '/src/config.php';
require_once __DIR__ . '/src/functions.php';
// Remove the composer install requirement by
// manually handling autoloading
spl_autoload_register(function (string $class) {
$nsParts = explode('\\', $class);
array_shift($nsParts);
array_shift($nsParts);
array_unshift($nsParts, __DIR__, 'src');
$file = implode(DIRECTORY_SEPARATOR, $nsParts) . '.php';
if (file_exists($file))
{
require_once($file);
return true;
}
return false;
});
// Log notices/errors/warnings to file
set_error_handler(static function (
$errno,
$errstr,
$errfile,
$errline
) {
$msg = print_r([
'code' => error_code_name($errno),
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
], TRUE);
file_put_contents('kilo.log', $msg, FILE_APPEND);
return true;
}, -1);
set_exception_handler(static function (mixed $e) {
$msg = print_r([
'code' => $e->getCode(),
'codeName' => error_code_name($e->getCode()),
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
], TRUE);
file_put_contents('kilo.log', $msg, FILE_APPEND);
});
// ! Init with an IIFE
return (static function (int $argc, array $argv): int {
Termios::enableRawMode();
register_shutdown_function([Termios::class, 'disableRawMode']);
Editor::new($argc, $argv)->run();
return 0;
})($argc, $argv);