#!/usr/bin/env php
<?php
/**
 * Copyright © OXID eSales AG. All rights reserved.
 * See LICENSE file for license details.
 */

use OxidEsales\EshopCommunity\Internal\Framework\Console\Executor;
use OxidEsales\Facts\Facts;
use Symfony\Component\Console\Input\ArgvInput;
use Webmozart\PathUtil\Path;

$autoloadFileExist = false;
$autoloadFiles = [
    __DIR__ . '/../vendor/autoload.php',
    __DIR__ . '/../../vendor/autoload.php',
    __DIR__ . '/../../../vendor/autoload.php',
    __DIR__ . '/../../../../vendor/autoload.php',
];
foreach ($autoloadFiles as $autoloadFile) {
    if (file_exists($autoloadFile)) {
        require_once $autoloadFile;
        $autoloadFileExist = true;
        break;
    }
}

if (!$autoloadFileExist) {
    exit("autoload.php file was not found!");
}

$shopId = (int) (new ArgvInput())->getParameterOption(
    '--' . Executor::SHOP_ID_PARAMETER_OPTION_NAME,
    0
);
if ($shopId !== 0) {
    $_POST['shp'] = $shopId;
}
$bootstrapFilePath = Path::join((new Facts())->getSourcePath(), 'bootstrap.php');
require_once $bootstrapFilePath;

$factory = \OxidEsales\EshopCommunity\Internal\Container\ContainerFactory::getInstance();
$factory->getContainer()->get(OxidEsales\EshopCommunity\Internal\Framework\Console\ExecutorInterface::class)->execute();
