summaryrefslogtreecommitdiff
path: root/public/index.php
blob: 3d82924572b288a5d411bcb64bb931c51cfc550f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

use FlatFileForms\App;
use Yosymfony\Toml\Toml;

require_once dirname(__DIR__) . '/vendor/autoload.php';

function findAppConfigFile($path)
{
  $currentDirectory = $path;
  while ($currentDirectory !== '/') {
    $configFile = $currentDirectory . '/config.toml';
    if (file_exists($configFile)) {
      return $configFile;
    }

    $currentDirectory = dirname($currentDirectory);
  }

  die('config.toml missing');
}

$configFile = findAppConfigFile(dirname(__DIR__));
$config = Toml::parseFile($configFile);

chdir(dirname($configFile));
$contentDirectoryPath = realpath($config['app']['contentFolderPath']);
$contentDirectoryPath === false && die('Content folder "' . $config['app']['contentFolderPath'] . '" missing');
$config['app']['contentFolderPath'] = $contentDirectoryPath;
chdir($_SERVER['DOCUMENT_ROOT']);

foreach ($config as $key => $value) {
  $_ENV[$key] = $value;
}

new App();