#!/usr/bin/env php
<?php

require __DIR__.'/../vendor/autoload.php';

use App\Application;
use Awurth\Slim\Helper\Command\RequireFileCommand;
use Awurth\Slim\Helper\Command\RoutesCommand;
use Awurth\Slim\Helper\Command\SentinelCreateUserCommand;
use Symfony\Component\Console\Application as Console;
use Symfony\Component\Dotenv\Dotenv;

if (!isset($_SERVER['APP_ENV'])) {
    if (!class_exists(Dotenv::class)) {
        throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
    }
    (new Dotenv())->load(__DIR__.'/../.env');
}

$app = new Application($_SERVER['APP_ENV'] ?? 'dev');
$container = $app->getContainer();

$console = new Console();

$console->add(new RequireFileCommand($app->getConfigurationDir().'/database/index.php', 'db', 'Update database schema'));
$console->add(new RoutesCommand($container['router'], $container['settings']['rest']));
$console->add(new SentinelCreateUserCommand($container['sentinel']));

$console->run();
