#!/usr/bin/env php
<?php
/**
 * CoreShop.
 *
 * This source file is subject to the GNU General Public License version 3 (GPLv3)
 * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
 * files that are distributed with this source code.
 *
 * @copyright  Copyright (c) CoreShop GmbH (https://www.coreshop.org)
 * @license    https://www.coreshop.org/license     GPLv3 and CCL
 */

ob_get_clean();

if (file_exists($a = getcwd() . '/vendor/autoload.php')) {
    include $a;
} elseif (file_exists($a = __DIR__ . '/../../../../vendor/autoload.php')) {
    include $a;
} elseif (file_exists($a = __DIR__ . '/../vendor/autoload.php')) {
    include $a;
} else {
    fwrite(STDERR, 'Cannot locate autoloader; please run "composer install"' . PHP_EOL);
    exit(1);
}

\Pimcore\Bootstrap::setProjectRoot();

define('PIMCORE_CONSOLE', true);


$input = new \Symfony\Component\Console\Input\ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
    putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
    putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

/** @var \Pimcore\Kernel $kernel */
$kernel = \Pimcore\Bootstrap::startupCli();
$application = new \Pimcore\Console\Application($kernel);
$application->run();
