guillaumemonet/Rad

View on GitHub
bin/rad

Summary

Maintainability
Test Coverage
#!/usr/bin/env php
<?php

declare(strict_types=1);

use Rad\Composer\Manager;
use Rad\Rad;

$rootDir = realpath(__DIR__ . '/../');

// Autoloader for standalone install (installed via `composer create-project` or cloned locally)
$autoloader = realpath($rootDir . '/vendor/autoload.php');

if (!$autoloader) {
    // Installed via `composer [global] require`.
    $autoloader = realpath($rootDir . '/../../autoload.php');
}

if (!$autoloader) {
    throw new RuntimeException(
                    'RAD Framework was unable to its autoloader. ' .
                    'Did you forget to run "composer update"?'
    );
}

require_once $autoloader;

$app = new Rad($rootDir . "/config/");

$actionName = $argv[1];

switch ($actionName) {
    case 'build':
        fireBuild($argv);
        break;
    case 'clearCache':
        fireClearCache($arv);
        break;
    case 'printRoute':
        print_r($app->getRouter()->getRoutes());
        break;
}

function fireBuild($argv) {
    Manager::build($argv);
}

function fireClearCache($argv) {
    Manager::clean();
}

function checkArg($arg, $position, $message) {
    if (!isset($arg[$position])) {
        throw new RuntimeException(
                        $message
        );
    }
}