kahlan/kahlan

View on GitHub
bin/kahlan

Summary

Maintainability
Test Coverage
#!/usr/bin/env php
<?php
if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}

error_reporting(E_ALL^E_NOTICE);

define('KAHLAN_CWD', realpath(getcwd()));
$pwd = KAHLAN_CWD;
$vendorName = 'vendor';

if (file_exists($composerPath = "{$pwd}/composer.json")) {
    $composerJson = json_decode(file_get_contents($composerPath), true);
    $vendorName = isset($composerJson['config']['vendor-dir']) ? $composerJson['config']['vendor-dir'] : $vendorName;
}

$autoload = require __DIR__ . '/../autoload.php';
$autoloader = $autoload("{$pwd}/{$vendorName}");

use Kahlan\Box\Box;
use Kahlan\Suite;
use Kahlan\Cli\Kahlan;
use Kahlan\Jit\ClassLoader;

require __DIR__ . '/../src/functions.php';
$GLOBALS['__composer_autoload_files']['337663d83d8353cc8c7847676b3b0937'] = true;

$box = \Kahlan\box('kahlan', new Box());

$box->service('suite.global', function() {
    return new Suite();
});

$specs = new Kahlan([
    'autoloader' => $autoloader,
    'suite'      => $box->get('suite.global')
]);
$specs->loadConfig($argv);
initKahlanGlobalFunctions();

if ($autoloader instanceof ClassLoader) {
    $commandLine = $specs->commandLine();
    $autoloader->patch([
        'include'    => $commandLine->get('include'),
        'exclude'    => array_merge($commandLine->get('exclude'), ['Kahlan\\']),
        'persistent' => $commandLine->get('persistent'),
        'cachePath'  => rtrim(realpath(sys_get_temp_dir()), DS) . DS . 'kahlan',
        'clearCache' => $commandLine->get('cc')
    ]);

    $specs->initPatchers();

    foreach ($autoloader->files() as $fileIdentifier => $file) {
        if (!empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
            continue;
        }
        $autoloader->loadFile($file);
        $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
    }
}

if (!file_exists("{$pwd}/{$vendorName}/autoload.php")) {
    echo "\033[1;31mYou need to set up the project dependencies using the following commands: \033[0m" . PHP_EOL;
    echo 'curl -s http://getcomposer.org/installer | php' . PHP_EOL;
    echo 'php composer.phar install' . PHP_EOL;
    exit(1);
}

error_reporting(E_ALL);
$specs->run();
exit($specs->status());