<?php
$databases = $app->getContainer()->get('databases');
foreach ($databases->databases as $name => $settings) {
  switch ($settings->engine) {
    case 'mysql': {
      $dsn = ["mysql:host={$settings->host->name}"];
      if (isset($settings->host->port)) {
        $dsn []= "port={$settings->host->port}";
      }
      $dsn []= "dbname={$settings->name}";
      $dsn = implode(';', $dsn);
      $config = [
        'connection_string' => $dsn,
        'username' => $settings->user->name,
        'password' => $settings->user->password
      ];
      Model::configure($config, null, $name);
      Model::set_db(new PDO($dsn, $settings->user->name, $settings->user->password), $name);
      break;
    }
    case 'sqlite': {
      $dsn = "sqlite:{$settings->database}";
      Model::configure($dsn, null, $name);
      break;
    }
  }
}
if (isset($databases->short_names) and $databases->short_names) {
  Model::$short_table_names = true;
}
