#!/usr/bin/env php
<?php
set_time_limit(0);

require dirname(__FILE__).'/vendor/autoload.php';

use Symfony\Component\Console\Application;

$composerData = json_decode(file_get_contents('composer.json'));
$name = key(current($composerData->autoload));
$dir = current(current($composerData->autoload));

$app = new Application();

$s = DIRECTORY_SEPARATOR;
$iterator = new \RecursiveIteratorIterator(
    new \RecursiveDirectoryIterator("$dir$name{$s}DebugCommand")
);

foreach ($iterator as $fileinfo) {
    if ($fileinfo->isFile() and 'php' === strtolower($fileinfo->getExtension())) {
        $path = $fileinfo->getPathName();
        $className = str_replace([$dir, '.php', '/'], ['', '', '\\'], $path);
        $class = (new \ReflectionClass($className));
        if ($class->isAbstract() or $class->isInterface()) {
            continue;
        }
        $app->add(new $className());
    }
}
$app->run();
