#!/usr/bin/env php
<?php
/**
 * @copyright Bluz PHP Team
 * @link https://github.com/bluzphp/bluzman
 */

if (PHP_SAPI !== 'cli') {
    die('Must run from command line');
}
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    // sorry windows lovers
    throw new \Exception();
}

// Root path, double level up
// UP to root from "/application/vendor/bluzphp/bluzman/bin"
$root = realpath(dirname(__DIR__, 4));

// Definitions
define('DS', DIRECTORY_SEPARATOR);

defined('PATH_ROOT') ? : define('PATH_ROOT', $root);
defined('PATH_APPLICATION') ? : define('PATH_APPLICATION', $root . '/application');
defined('PATH_DATA') ? : define('PATH_DATA', $root . '/data');
defined('PATH_VENDOR') ? : define('PATH_VENDOR', $root . '/vendor');
defined('PATH_PUBLIC') ? : define('PATH_PUBLIC', $root . '/public');

// Environment
$env = getenv('BLUZ_ENV') ?: 'production';
define('BLUZ_ENV', $env);

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
ini_set('log_errors', 0);
ini_set('html_errors', 0);

// Get project info from composer.json
$composerConfig = json_decode(
    file_get_contents(PATH_VENDOR .DS. 'bluzphp' .DS. 'bluzman' .DS. 'composer.json'),
    true
);
require_once PATH_VENDOR . '/autoload.php';

$application = new Bluzman\Application\Application(
    $composerConfig['description'],
    $composerConfig['version'] ?? 'dev'
);
$application->init();
$application->run();
