<?php
use DI\ContainerBuilder as Builder;

include_once 'composer.php';

$builder = new Builder();

$folders = [
  implode(DIRECTORY_SEPARATOR, [
    dirname(__DIR__, 2),
    'setup',
    'env'
  ]),
  implode(DIRECTORY_SEPARATOR, [
    dirname(__DIR__, 2),
    'setup',
    'common'
  ]),
  implode(DIRECTORY_SEPARATOR, [
    __DIR__,
    'ws'
  ])
];
$files = [
  'settings',
  'setups'
];
foreach ($files as $file) {
  foreach ($folders as $folder) {
    $filename = implode(DIRECTORY_SEPARATOR, [
      $folder,
      $file . '.php'
    ]);
    if (!file_exists($filename)) {
      continue;
    }
    $builder->addDefinitions($filename);
  }
}

$container = $builder->build();
$app = $container->get(Ratchet\Server\IoServer::class);

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