diff options
Diffstat (limited to 'src/Kernel.php')
-rw-r--r-- | src/Kernel.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Kernel.php b/src/Kernel.php new file mode 100644 index 0000000..29785a8 --- /dev/null +++ b/src/Kernel.php @@ -0,0 +1,51 @@ +<?php + +namespace Elements; + +class Kernel +{ + private static array $config = []; + + /** + * Kernel initialization. + */ + public static function init() + { + $configFile = self::findAppConfigFile(dirname(__DIR__)); + $config = include $configFile; + foreach ($config as $key => $value) { + self::$config[$key] = $value; + } + + Template::init(); + DB::init(); + new Router(); + } + + /** + * Find app config file in parent directories + */ + private static function findAppConfigFile(string $path): string + { + $currentDirectory = $path; + while ($currentDirectory !== '/') { + $configFile = $currentDirectory . '/config.php'; + if (file_exists($configFile)) { + return $configFile; + } + + $currentDirectory = dirname($currentDirectory); + } + + die('config.php missing'); + } + + /** + * Get config value + */ + public static function config($key): mixed + { + return self::$config[$key]; + } +} + |