SerafimArts/Pipe

View on GitHub
bin/pipe

Summary

Maintainability
Test Coverage
#!/usr/bin/env php
<?php
/**
 * This file is part of Pipe package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
declare(strict_types=1);


use Composer\Autoload\ClassLoader;
use Symfony\Component\Console\Application;
use Serafim\Pipe\Console\BuildAutocompleteCommand;


/*
 |--------------------------------------------------------------------------
 | Register The Auto Loader
 |--------------------------------------------------------------------------
 |
 | Composer provides a convenient, automatically generated class loader
 | for our application. We just need to utilize it! We'll require it
 | into the script here so that we do not have to worry about the
 | loading of any our classes "manually". Feels great to relax.
 |
 */

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


foreach ($autoloadPaths as $path) {
    if (\is_file($path) && \is_readable($path)) {
        /** @var ClassLoader $classLoader */
        $classLoader = require_once $path;
        break;
    }
}


if (! isset($classLoader) || ! $classLoader) {
    $error =
        'Could not find autoload.php file.' . \PHP_EOL .
        'You need to set up the project dependencies using Composer:' . \PHP_EOL . \PHP_EOL .
        '    composer install' . \PHP_EOL . \PHP_EOL .
        'You can learn all about Composer on https://getcomposer.org/.' . \PHP_EOL;
    throw new \LogicException($error);
}


/*
 |--------------------------------------------------------------------------
 | Create The Application
 |--------------------------------------------------------------------------
 |
 | The first thing we will do is create a new Railt Application instance
 | which serves as the "glue" for all the components of Railt, and is
 | the dependency injection container for the system binding all of the
 | various parts.
 |
 */


try {
    $app = new Application();
    $app->add(new BuildAutocompleteCommand());
} catch (\Throwable $e) {
    throw new \LogicException('Could not start an application: ' . $e->getMessage());
}


/*
 |--------------------------------------------------------------------------
 | Run The Console Application
 |--------------------------------------------------------------------------
 |
 | When we run the console application, the current CLI command will be
 | executed in this console and the response sent back to a terminal
 | or another output device for the developers. Here goes nothing!
 |
 */


try {
    $code = $app->run();
} catch (\Throwable $e) {
    \fwrite(\STDERR, $e->getMessage());
    $code = $e->getCode() ?: 1;
} finally {
    exit($code);
}