本文整理汇总了PHP中Guzzle\Service\Command\CommandInterface::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP CommandInterface::getRequest方法的具体用法?PHP CommandInterface::getRequest怎么用?PHP CommandInterface::getRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Service\Command\CommandInterface
的用法示例。
在下文中一共展示了CommandInterface::getRequest方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addMd5
private function addMd5(CommandInterface $command)
{
$request = $command->getRequest();
if ($body = $request->getBody()) {
if (false !== ($md5 = $body->getContentMd5(true, true))) {
$request->setHeader('Content-MD5', $md5);
}
}
}
示例2: addMd5
private function addMd5(CommandInterface $command)
{
$request = $command->getRequest();
if ($body = $request->getBody()) {
if (false === ($md5 = $body->getContentMd5(true, true))) {
throw new RuntimeException('Unable to add a MD5 checksum');
}
$request->setHeader('Content-MD5', $md5);
}
}
示例3: parse
public function parse(CommandInterface $command)
{
$response = $command->getRequest()->getResponse();
if ($contentType = $command['command.expects']) {
$response->setHeader('Content-Type', $contentType);
} else {
$contentType = (string) $response->getHeader('Content-Type');
}
return $this->handleParsing($command, $response, $contentType);
}
示例4: fromCommand
/**
* {@inheritDoc}
*/
public static function fromCommand(CommandInterface $command, Response $response)
{
$errors = json_decode($response->getBody(true), true);
$type = array_get($errors, 'error.type', null);
$code = array_get($errors, 'error.code', null);
$message = array_get($errors, 'error.message', null);
$class = '\\Apache\\Usergrid\\Api\\Exception\\' . studly_case($type) . 'Exception';
if (class_exists($class)) {
$exception = new $class($message, $response->getStatusCode());
} else {
$exception = new static($message, $response->getStatusCode());
}
$exception->setErrorType($type);
$exception->setResponse($response);
$exception->setRequest($command->getRequest());
return $exception;
}
示例5: parse
/**
* {@inheritdoc}
*
* @param CommandInterface $command
* @return array|MultiResultResponse|SingleResultResponse|Response|mixed
*/
public function parse(CommandInterface $command)
{
$response = $command->getRequest()->getResponse();
if ($response === null) {
return null;
}
$responseArray = $this->parseResponseIntoArray($response);
// If there is no Body, just return the Response
if (!$response->getBody()) {
return $response;
}
// Handle multi-result responses
if (array_key_exists('results', $responseArray)) {
return $this->createMultiResultResponse($response);
}
return $this->createSingleResultResponse($response);
}
示例6: fromCommand
/**
* {@inheritDoc}
*/
public static function fromCommand(CommandInterface $command, Response $response)
{
$errors = json_decode($response->getBody(true), true);
$type = $errors['error']['type'];
$message = isset($errors['error']['message']) ? $errors['error']['message'] : 'Unknown error';
$code = isset($errors['error']['code']) ? $errors['error']['code'] : null;
// We can trigger very specific exception based on the type and code
if ($type === 'card_error') {
$exception = new CardErrorException($message, $response->getStatusCode());
} elseif ($type === 'invalid_request_error' && $code === 'rate_limit') {
$exception = new ApiRateLimitException($message, $response->getStatusCode());
} else {
$exception = new static($message, $response->getStatusCode());
}
$exception->setRequest($command->getRequest());
$exception->setResponse($response);
return $exception;
}
示例7: getExceptionForFailedCommand
/**
* Get the Exception that caused the given $command to fail
*
* @param CommandInterface $command Failed command
*
* @return \Exception|null
*/
public function getExceptionForFailedCommand(CommandInterface $command)
{
return $this->getExceptionForFailedRequest($command->getRequest());
}
示例8: parse
/**
* {@inheritdoc}
*/
public function parse(CommandInterface $command)
{
$response = $command->getRequest()->getResponse();
$contentType = (string) $response->getHeader('Content-Type');
return $this->handleParsing($command, $response, $contentType);
}
示例9: execute
/**
* Execute a command and return the response
*
* @param CommandInterface|CommandSet|array $command Command or set to execute
*
* @return mixed Returns the result of the executed command's
* {@see CommandInterface::getResult} method if a CommandInterface is
* passed, or the CommandSet itself if a CommandSet is passed
* @throws InvalidArgumentException if an invalid command is passed
* @throws CommandSetException if a set contains commands associated
* with other clients
*/
public function execute($command)
{
if ($command instanceof CommandInterface) {
$command->setClient($this)->prepare();
$this->dispatch('command.before_send', array('command' => $command));
$command->getRequest()->send();
$this->dispatch('command.after_send', array('command' => $command));
return $command->getResult();
} else {
if ($command instanceof CommandSet) {
foreach ($command as $c) {
if ($c->getClient() && $c->getClient() !== $this) {
throw new CommandSetException('Attempting to run a mixed-Client CommandSet from a ' . 'Client context. Run the set using CommandSet::execute() ');
}
$c->setClient($this);
}
return $command->execute();
} else {
if (is_array($command)) {
return $this->execute(new CommandSet($command));
}
}
}
throw new InvalidArgumentException('Invalid command sent to ' . __METHOD__);
}
示例10: parse
/**
* {@inheritdoc}
*/
public function parse(CommandInterface $command)
{
$content = $command->getRequest()->getResponse()->getBody(true);
return json_decode(preg_replace('/^availableFeeds=/', '', $content), true);
}