<?php
use DI\ContainerBuilder as Builder;
use DI\Bridge\Slim\Bridge;

include_once 'composer.php';

$builder = new Builder();
$folders = [
  'settings',
  'setups'
];
foreach ($folders as $folder) {
  $name = implode(DIRECTORY_SEPARATOR, [__DIR__, $folder]);
  if (!file_exists($name)) {
    continue;
  }
  $files = new DirectoryIterator($name);
  foreach ($files as $file) {
    if ($file->isDir()) {
      continue;
    }
    $builder->addDefinitions($file->getRealPath());
  }
}

$container = $builder->build();
#!d($container->getKnownEntryNames());
$app = Bridge::create($container);

$app->addBodyParsingMiddleware();

$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'middlewares']);
if (file_exists($folder)) {
  $files = new DirectoryIterator($folder);
  foreach ($files as $file) {
    if ($file->isDir()) {
      continue;
    }
    include_once $file->getRealPath();
  }
}

include_once 'databases.php';
include_once 'router.php';
