/** * @param CommandInterface $command * @param array|string $args * * @throws CommandException * @throws Exception * @return mixed */ public function execute(CommandInterface $command, $args) { $return = false; if ($result = $command->run($args)) { $general = array('user' => $this->adminUsername, 'password' => $this->adminPassword, 'returncode' => $command->getReturnCode(), 'cmd' => $command->getCommand()); $argumentArray = array(); for ($i = 0; $i < count($args); $i++) { $argumentArray['arg' . ($i + 1)] = $args[$i]; } $postVars = array_merge($general, $argumentArray); $commandResult = $this->http->send($postVars); if ($commandResult == self::RESULT_E_PASSWORD) { throw new CommandException('Invalid password', self::RESULT_E_PASSWORD); } elseif ($commandResult == self::RESULT_E_DISK) { throw new CommandException('Not enough free diskspace to perform the request', self::RESULT_E_DISK); } elseif ($commandResult == self::RESULT_E_ARGS) { throw new CommandException('Incorrect usage; invalid or missing arguments', self::RESULT_E_ARGS); } elseif ($commandResult == self::RESULT_E_LIMIT) { throw new CommandException('Hosting package limits reached', self::RESULT_E_LIMIT); } elseif ($commandResult == self::RESULT_E_EXISTS) { throw new CommandException('Given object already exists', self::RESULT_E_EXISTS); } $result = $command->check($commandResult); if ($result == null) { throw new Exception('Command should either return true or false in the check() method', ErrorCodes::ERROR_INVALID_COMMAND); } // return true if the command executed successfully $return = $result && $commandResult == self::RESULT_OK; } if ($result == null) { throw new Exception('Command should either return true or false in the run() method', ErrorCodes::ERROR_INVALID_COMMAND); } return $return; }
/** * @param array $arguments * * @return mixed * @throws \VestaCP\Command\Exception * @throws \VestaCP\Exception */ public function executeCommand(array $arguments) { $this->command->setArguments($arguments); return $this->client->execute($this->command, $arguments); }