#!/usr/bin/env php
<?php
// @link https://www.tomasvotruba.cz/blog/2018/08/02/5-gotchas-of-the-bin-file-in-php-cli-applications/

if (PHP_SAPI !== 'cli') {
    return;
}

gc_disable(); // performance boost

if (\Phar::running()) {
    $possibleAutoloadPaths = [
        'phar://phpcompatinfo.phar/config/bootstrap.php'
    ];
} else {
    $possibleAutoloadPaths = [
        // local dev repository
        dirname(__DIR__) . '/config/bootstrap.php',
    ];
}

$isAutoloadFound = false;
foreach ($possibleAutoloadPaths as $possibleAutoloadPath) {
    if (file_exists($possibleAutoloadPath)) {
        require_once $possibleAutoloadPath;
        $isAutoloadFound = true;
        break;
    }
}

if ($isAutoloadFound === false) {
    throw new RuntimeException(sprintf(
        'Unable to find "config/bootstrap.php" in "%s" paths.',
        implode('", "', $possibleAutoloadPaths)
    ));
}

use Bartlett\CompatInfo\Console\ApplicationInterface;

/** @var \Symfony\Component\DependencyInjection\ContainerBuilder $container */
$container = require dirname(__DIR__) . '/config/container.php';

$app = $container->get(ApplicationInterface::class);
$app->setContainer($container);
exit($app->run());
