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

/*
 * HiDev - integrate your development.
 *
 * @link      http://hidev.me/
 * @package   hidev
 * @license   BSD 3-clause
 * @copyright Copyright (c) 2015 HiQDev
 */

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));

$autoload_path = __DIR__ . '/vendor/autoload.php';
if (!file_exists($autoload_path)) {
    system("composer install");
}

require($autoload_path);
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');

Yii::setLogger(Yii::createObject('hidev\components\Logger'));

$application = new hidev\components\Application([
    'id'                    => 'hidev',
    'name'                  => 'HiDev - integrate your development',
    'basePath'              => __DIR__,
    'enableCoreCommands'    => false,
    'controllerNamespace'   => 'hidev\\controllers',
    'defaultRoute'          => 'default',
    'bootstrap'             => ['log', 'config'],
    'components'            => [
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning', 'info'],
                ],
            ],
        ],
        'robo' => [
            'class' => 'hidev\goals\Robo',
        ],
        'config' => [
            'class' => 'hidev\goals\Config',
        ],
        'request' => [
            'class' => 'hidev\components\Request',
        ],
        'view' => [
            'class' => 'hidev\components\View',
            'theme' => [
                'basePath' => '@config/templates',
                'pathMap' => [
                    '@app/views' => '@config/templates',
                ],
            ],

        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
    ],
]);

$exitCode = $application->run();
exit($exitCode);

function d ()
{
    foreach (func_get_args() as $a) {
        var_dump($a);
    }
    die();
}
