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

declare(strict_types=1);

gc_disable(); // performance boost

if (\Phar::running()) {
    $possibleAutoloadPaths = [
        'phar://umlwriter.phar/vendor/autoload.php'
    ];
} else {
    $possibleAutoloadPaths = [
        // local dev repository
        __DIR__ . '/../vendor/autoload.php',
        // dependency
        __DIR__ . '/../../../../vendor/autoload.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 "vendor/autoload.php" in "%s" paths.',
        implode('", "', $possibleAutoloadPaths)
    ));
}

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

use Bartlett\UmlWriter\Console\Application;
use Bartlett\UmlWriter\Service\ContainerService;

$application = new Application(new ContainerService());
$application->run();
