From da0d49a8472a3472ed24c99ed08435bf43a2ca3f Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 2 Jan 2022 13:57:40 +0100 Subject: Add config and make configurable --- .gitignore | 1 + config.example.toml | 6 ++++++ public/index.php | 29 +++++++++++++++++++++++++++++ src/App.php | 6 +++--- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 config.example.toml diff --git a/.gitignore b/.gitignore index 49b567d..a23bab3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor/ /content/ +/config.toml diff --git a/config.example.toml b/config.example.toml new file mode 100644 index 0000000..a506a09 --- /dev/null +++ b/config.example.toml @@ -0,0 +1,6 @@ +[app] +contentFolderPath = './content' + +[form] +entriesFolderName = 'entries' + 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 @@ $value) { + $_ENV[$key] = $value; +} + new App(); diff --git a/src/App.php b/src/App.php index fcf2699..7e0cabd 100644 --- a/src/App.php +++ b/src/App.php @@ -20,7 +20,7 @@ class App $content = [ 'data' => [], ]; - $contentRoot = dirname(__DIR__) . '/content'; + $contentRoot = $_ENV['app']['contentFolderPath']; $method = $request->getMethod(); $path = $request->getPathInfo(); @@ -85,7 +85,7 @@ class App $builder->addValue($entryKey, $entryValue); } - $entryDirectory = $formPath . '/entries/' . $date->format('Y/m/d'); + $entryDirectory = $formPath . '/' . $_ENV['form']['entriesFolderName'] . '/' . $date->format('Y/m/d'); @mkdir($entryDirectory, 0774, true); $entryFilename = $date->format('Ymd_Hi_') . hash('adler32', serialize($entry)) . '.toml'; file_put_contents( @@ -158,7 +158,7 @@ class App $config['api']['keys'] = $apiKeys; } - if (str_ends_with($currentFolder, '/content') || $currentFolder == '/') { + if (str_ends_with($currentFolder, '/' . basename($_ENV['app']['contentFolderPath'])) || $currentFolder == '/') { break; } -- cgit v1.2.3