summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2022-01-02 13:57:40 +0100
committerDaniel Weipert <code@drogueronin.de>2022-01-10 11:29:13 +0100
commitda0d49a8472a3472ed24c99ed08435bf43a2ca3f (patch)
tree0e4728c2029347c157913e9e4ba37e634a95ad1e /public
parent7783aeb63ec08bed159942fb0df100cfc4e93d3c (diff)
Add config and make configurable
Diffstat (limited to 'public')
-rw-r--r--public/index.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/public/index.php b/public/index.php
index 1cd408e..b7895e7 100644
--- a/public/index.php
+++ b/public/index.php
@@ -1,8 +1,37 @@
<?php
use FlatFileForms\App;
+use Yosymfony\Toml\Toml;
require_once dirname(__DIR__) . '/vendor/autoload.php';
+function findAppConfigFile($path)
+{
+ $currentFolder = $path;
+ while ($currentFolder !== '/') {
+ $configFile = $currentFolder . '/config.toml';
+ if (file_exists($configFile)) {
+ return $configFile;
+ }
+
+ $currentFolder = dirname($currentFolder);
+ }
+
+ die('config.toml missing');
+}
+
+$configFile = findAppConfigFile(dirname(__DIR__));
+$config = Toml::parseFile($configFile);
+
+chdir(dirname($configFile));
+$contentFolderPath = realpath($config['app']['contentFolderPath']);
+$contentFolderPath === false && die('Content folder "' . $config['app']['contentFolderPath'] . '" missing');
+$config['app']['contentFolderPath'] = $contentFolderPath;
+chdir($_SERVER['DOCUMENT_ROOT']);
+
+foreach ($config as $key => $value) {
+ $_ENV[$key] = $value;
+}
+
new App();