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

set_time_limit(0);

$app = require dirname(dirname(__FILE__)) . '/app/bootstrap.php';

use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\HelperSet;
use Application\Command\Storage;
use Application\Command\Database;
use Application\Command\Translations;

$consoleApp = new Application(
    $app['name'],
    $app['version']
);

$app->boot();

/********** Doctrine **********/
$doctrineHelperSet = new HelperSet([
    'db' => new ConnectionHelper(
        $app['orm.em']->getConnection()
    ),
    'em' => new EntityManagerHelper(
        $app['orm.em']
    )
]);

$consoleApp->setHelperSet($doctrineHelperSet);
ConsoleRunner::addCommands(
    $consoleApp
);

/*************** Application ***************/
/********** Storage **********/
$consoleApp
    ->add(
        new Storage\PrepareCommand(
            'application:storage:prepare',
            $app
        )
    )
;

/********** Database **********/
$consoleApp
    ->add(
        new Database\HydrateDataCommand(
            'application:database:hydrate-data',
            $app
        )
    )
;

/********** Translations **********/
$consoleApp
    ->add(
        new Translations\PrepareCommand(
            'application:translations:prepare',
            $app
        )
    )
;

$consoleApp->run();
