/** * Returns the full command. * * @return string * * @throws \YapepBase\Exception\Shell\Exception If no command is set. */ public function getCommand() { $command = escapeshellarg($this->command); foreach ($this->commandParams as $param) { if (strlen($param['option']) > 0) { $command .= ' ' . $param['option']; if (strlen($param['value']) > 0) { $command .= $this->switchValueSeparator . escapeshellarg($param['value']); } } else { $command .= ' ' . escapeshellarg($param['value']); } } foreach ($this->outputRedirections as $type => $target) { $command .= ' ' . $type . ' ' . $target; } if (!empty($this->chainedCommand)) { $command .= ' ' . $this->chainedCommandOperator . ' ' . $this->chainedCommand->getCommand(); } return $command; }
/** * Runs a command and throws an exception if the run fails. * * @param ICommandExecutor $command The command to run. * @param string $exceptionMessage The message of the exception. * * @return \YapepBase\Shell\CommandOutput The output of the command. * * @throws \YapepBase\Exception\File\Exception If the command failed to run. */ protected function runCommandAndThrowExceptionIfFailed(ICommandExecutor $command, $exceptionMessage) { $result = $command->run(); if (!$result->isSuccessful()) { throw new Exception($exceptionMessage, 0, null, $result); } return $result; }