summaryrefslogtreecommitdiff
path: root/public/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'public/index.php')
-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();