summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2022-01-27 22:57:25 +0100
committerDaniel Weipert <code@drogueronin.de>2022-01-27 22:57:25 +0100
commit88880f14dff2731838953b937692f87620750f69 (patch)
treeca4fc7f08986793523c196b3da824edc3c4c6ac7
parent27a1680fe386db99fd983eba64533091b9451d27 (diff)
Add Kernel with configHEADmain
-rw-r--r--.gitignore2
-rw-r--r--config.example.php7
-rw-r--r--public/index.php6
-rw-r--r--src/Kernel.php51
4 files changed, 63 insertions, 3 deletions
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 @@
+<?php
+
+return [
+ 'environment' => '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 @@
<?php
+use Elements\Kernel;
+
require_once dirname(__DIR__) . '/vendor/autoload.php';
-\Elements\Template::init();
-\Elements\DB::init();
-new \Elements\Router();
+Kernel::init();
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];
+ }
+}
+