Exemple #1
0
 /**
  * @param CM_Cli_Arguments $arguments
  * @throws CM_Exception
  * @return int
  */
 public function run(CM_Cli_Arguments $arguments)
 {
     $method = new ReflectionMethod($this, 'configure');
     $parameters = $arguments->extractMethodParameters($method);
     $method->invokeArgs($this, $parameters);
     try {
         $packageName = $arguments->getNumeric()->shift();
         $methodName = $arguments->getNumeric()->shift();
         if (!$packageName) {
             $this->_outputError($this->getHelp());
             return 1;
         }
         if (!$methodName) {
             $this->_outputError($this->getHelp($packageName));
             return 1;
         }
         $process = $this->_getProcess();
         $command = $this->_getCommand($packageName, $methodName);
         if ($command->getSynchronized()) {
             $this->monitorSynchronizedCommands();
             $this->_checkLock($command);
             $this->_lockCommand($command);
             $process->bind('exit', function () use($command) {
                 $this->unlockCommand($command);
             });
         }
         $transactionName = 'cm ' . $packageName . ' ' . $methodName;
         $streamInput = $this->_streamInput;
         $streamOutput = $this->_streamOutput;
         $streamError = $this->_streamError;
         $workload = $this->_getProcessWorkload($transactionName, $command, $arguments, $streamInput, $streamOutput, $streamError);
         $forks = max($this->_forks, 1);
         for ($i = 0; $i < $forks; $i++) {
             $process->fork($workload);
         }
         $resultList = $process->waitForChildren($command->getKeepalive());
         if ($command->getSynchronized()) {
             $this->unlockCommand($command);
         }
         $failure = Functional\some($resultList, function (CM_Process_WorkloadResult $result) {
             return !$result->isSuccess();
         });
         if ($failure) {
             return 1;
         }
         return 0;
     } catch (CM_Cli_Exception_Internal $e) {
         $this->_outputError('ERROR: ' . $e->getMessage() . PHP_EOL);
         return 1;
     }
 }
Exemple #2
0
 /**
  * @param CM_Cli_Arguments $arguments
  * @return array
  * @throws CM_Cli_Exception_InvalidArguments
  */
 public function extractParameters(CM_Cli_Arguments $arguments)
 {
     $parameters = $arguments->extractMethodParameters($this->_method);
     return $parameters;
 }