Exemplo n.º 1
0
 protected function setPropertiesFromInput(Input $input)
 {
     foreach ($input->getAll() as $key => $result) {
         $this->{$key} = $result;
     }
 }
Exemplo n.º 2
0
 public function call($commandName, $args = [])
 {
     $output = $this->getOutputHandler();
     try {
         $command = $this->getCommand($commandName);
         $signature = $command->getSignature();
         $indexedArgNames = array_map(function ($arg) {
             return $arg['name'];
         }, $signature['args']);
         // create $argv style array from args
         $argvOpts = array_map(function () {
             return null;
         }, $indexedArgNames);
         $argvArgs = [];
         foreach ($args as $key => $value) {
             if (strpos($key, '-') === 0) {
                 if ($value !== false) {
                     if (strpos($key, '--') === 0) {
                         if ($value === true) {
                             $argvArgs[] = $key;
                         } else {
                             $argvArgs[] = $key . '=' . $value;
                         }
                     } else {
                         if ($value === true) {
                             $argvArgs[] = $key;
                         } else {
                             $argvArgs[] = $key;
                             $argvArgs[] = $value;
                         }
                     }
                 }
             } else {
                 $index = array_search($key, $indexedArgNames);
                 if ($index !== false) {
                     $argvOpts[$index] = $value;
                 }
             }
         }
         $input = new Input(array_merge($argvOpts, $argvArgs));
         $input->parseAndValidate($signature);
         return $command->run($input, $output);
     } catch (\Exception $e) {
         $output->error($e->getMessage());
     }
 }