Added shutdown handler (for cli only) to clear cache

ref #38 https://git.n64.cc/nosial/ncc/-/issues/38
This commit is contained in:
Netkas 2022-12-06 01:32:16 -05:00
parent 6371f26046
commit f08ecb7947

View file

@ -12,6 +12,7 @@
use ncc\ncc;
use ncc\Utilities\Console;
use ncc\Utilities\Resolver;
use ncc\Utilities\RuntimeCache;
class Main
{
@ -51,8 +52,8 @@
Console::outException('Cannot initialize NCC due to a runtime error.', $e, 1);
}
// Define CLI stuff
define('NCC_CLI_MODE', 1);
register_shutdown_function('ncc\CLI\Main::shutdown');
if(isset(self::$args['l']) || isset(self::$args['log-level']))
{
@ -82,13 +83,14 @@
if(Resolver::checkLogLevel(self::$log_level, LogLevel::Debug))
{
Console::outDebug('Debug logging enabled');
Console::outDebug(sprintf('consts: %s', json_encode(ncc::getConstants(), JSON_UNESCAPED_SLASHES)));
/** @noinspection PhpUnhandledExceptionInspection */
Console::outDebug(sprintf('const: %s', json_encode(ncc::getConstants(), JSON_UNESCAPED_SLASHES)));
Console::outDebug(sprintf('args: %s', json_encode(self::$args, JSON_UNESCAPED_SLASHES)));
}
if(in_array(NccBuildFlags::Unstable, NCC_VERSION_FLAGS))
{
//Console::outWarning('This is an unstable build of NCC, expect some features to not work as expected');
Console::outWarning('This is an unstable build of NCC, expect some features to not work as expected');
}
try
@ -152,4 +154,13 @@
return self::$log_level;
}
/**
* @return void
*/
public static function shutdown()
{
Console::outDebug('clearing cache');
RuntimeCache::clearCache();
}
}