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

declare(strict_types=1);

/*
 * This file is part of the TODO Registrar project.
 *
 * (c) Anatoliy Melnikov <5785276@gmail.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

use Aeliot\TodoRegistrar\ApplicationFactory;

$autoloaderPath = (static function (): string {
    if (Phar::running()) {
        return __DIR__ . '/../vendor/autoload.php';
    }

    if (isset($GLOBALS['_composer_autoload_path'])) {
        return $GLOBALS['_composer_autoload_path'];
    }

    $paths = [
        __DIR__ . '/../vendor/autoload.php',
        __DIR__ . '/../../vendor/autoload.php',
        __DIR__ . '/../../../vendor/autoload.php',
        __DIR__ . '/../../../../vendor/autoload.php',
    ];

    foreach ($paths as $path) {
        if (file_exists($path)) {
            return realpath($path);
        }
    }

    throw new RuntimeException('Cannot find autoloader');
})();

require_once $autoloaderPath;

exit((new ApplicationFactory())->create()->run());
