diff options
author | Daniel Weipert <code@drogueronin.de> | 2022-01-02 13:57:40 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2022-01-10 11:29:13 +0100 |
commit | da0d49a8472a3472ed24c99ed08435bf43a2ca3f (patch) | |
tree | 0e4728c2029347c157913e9e4ba37e634a95ad1e /public/index.php | |
parent | 7783aeb63ec08bed159942fb0df100cfc4e93d3c (diff) |
Add config and make configurable
Diffstat (limited to 'public/index.php')
-rw-r--r-- | public/index.php | 29 |
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(); |