Ejemplo n.º 1
0
 public static function routeCommand(ConsoleApplication $console)
 {
     // TODO - currently in PHP it is impossible to make a constructor of a child class
     // have a constructor that has more restricted visibility than then parent class.
     // In an ideal world, ConsoleApplication would be a child class that does not have a
     // default constructor, as that would prevent 'accidental' insertion of an unitialized
     // object.
     // However that is not currently possible, and would require an RFC to change.
     //Figure out what Command was requested.
     try {
         $parsedCommand = $console->parseCommandLine();
     } catch (\Exception $e) {
         //@TODO change to just catch parseException when that's implemented
         $output = new BufferedOutput();
         $console->renderException($e, $output);
         echo $output->fetch();
         exit(-1);
     }
     $output = $parsedCommand->getOutput();
     $formatter = $output->getFormatter();
     $formatter->setStyle('question', new OutputFormatterStyle('blue'));
     $formatter->setStyle('info', new OutputFormatterStyle('blue'));
     $questionHelper = new QuestionHelper();
     $questionHelper->setHelperSet($console->getHelperSet());
     $injectionParams = InjectionParams::fromParams($parsedCommand->getParams());
     $executable = new Executable($parsedCommand->getCallable(), $injectionParams);
     $executable->setAllowedToReturnNull(true);
     return $executable;
 }
Ejemplo n.º 2
0
function lowrey($params)
{
    $newParams = [];
    foreach ($params as $key => $value) {
        $newParams[':' . $key] = $value;
    }
    return $newParams;
}
$console = new Application();
$console->add(new AboutCommand());
$uploadCommand = new Command('upload', 'uploadFile');
$uploadCommand->addArgument('filename', InputArgument::REQUIRED, 'The name of the file to upload');
$uploadCommand->addOption('dir', null, InputArgument::OPTIONAL, 'Which directory to upload from', './');
$console->add($uploadCommand);
$helloWorldCallable = function ($name) {
    echo "Hello world, and particularly {$name}" . PHP_EOL;
};
$callableCommand = new Command('greet', $helloWorldCallable);
$callableCommand->addArgument('name', InputArgument::REQUIRED, 'The name of the person to say hello to.');
$callableCommand->setDescription("Says hello to the world and one named person");
$console->add($callableCommand);
try {
    $parsedCommand = $console->parseCommandLine();
} catch (\Exception $e) {
    $output = new BufferedOutput();
    $console->renderException($e, $output);
    echo $output->fetch();
    exit(-1);
}
$provider = new Auryn\Provider();
$provider->execute($parsedCommand->getCallable(), lowrey($parsedCommand->getParams()));