From 88880f14dff2731838953b937692f87620750f69 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 27 Jan 2022 22:57:25 +0100 Subject: Add Kernel with config --- .gitignore | 2 ++ config.example.php | 7 +++++++ public/index.php | 6 +++--- src/Kernel.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 config.example.php create mode 100644 src/Kernel.php diff --git a/.gitignore b/.gitignore index 7db1f9d..8a6b055 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /vendor/ db.sqlite +config.php +/plugins /public/artworks # Jetbrains diff --git a/config.example.php b/config.example.php new file mode 100644 index 0000000..11d878e --- /dev/null +++ b/config.example.php @@ -0,0 +1,7 @@ + 'production', + 'plugins_directory' => __DIR__ . '/plugins', +]; + diff --git a/public/index.php b/public/index.php index 022af48..85aad22 100644 --- a/public/index.php +++ b/public/index.php @@ -1,8 +1,8 @@ $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]; + } +} + -- cgit v1.2.3