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

if (PHP_VERSION_ID < 50400) {
    file_put_contents('php://stderr', sprintf(
        "Bricks Installer requires PHP 5.4 version or higher and your system has\n".
        "PHP %s version installed.\n\n".
        "To solve this issue, upgrade your PHP installation or install Bricks manually\n".
        "executing the following command:\n\n".
        "composer create-project bricks/framework-standard-edition <project-name> <bricks-version>\n\n",
        PHP_VERSION
    ));

    exit(1);
}

if (extension_loaded('suhosin')) {
    file_put_contents('php://stderr',
        "Bricks Installer is not compatible with the 'suhosin' PHP extension.\n".
        "Disable that extension before running the installer.\n\n".
        "Alternatively, install Bricks manually executing the following command:\n\n".
        "composer create-project bricks/framework-standard-edition <project-name> <bricks-version>\n\n"
    );

    exit(1);
}

require file_exists(__DIR__.'/vendor/autoload.php')
    ? __DIR__.'/vendor/autoload.php'
    : __DIR__.'/../../autoload.php';

$appVersion = '3.2.1';

// Windows uses Path instead of PATH
if (!isset($_SERVER['PATH']) && isset($_SERVER['Path'])) {
    $_SERVER['PATH'] = $_SERVER['Path'];
}

$app = new Bricks\Installer\Application('Bricks Installer', $appVersion);
$app->add(new Bricks\Installer\AboutCommand($appVersion));
$app->add(new Bricks\Installer\NewCommand());
$app->add(new Bricks\Installer\DemoCommand());
$app->add(new Bricks\Installer\SelfUpdateCommand());

$app->setDefaultCommand('about');

$app->run();
