本文整理汇总了PHP中Guzzle\Service\Command\CommandInterface::execute方法的典型用法代码示例。如果您正苦于以下问题:PHP CommandInterface::execute方法的具体用法?PHP CommandInterface::execute怎么用?PHP CommandInterface::execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Service\Command\CommandInterface
的用法示例。
在下文中一共展示了CommandInterface::execute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkExistenceWithCommand
/**
* Determines whether or not a resource exists using a command
*
* @param CommandInterface $command Command used to poll for the resource
* @param bool $accept403 Set to true if 403s are acceptable
*
* @return bool
* @throws S3Exception|\Exception if there is an unhandled exception
*/
protected function checkExistenceWithCommand(CommandInterface $command, $accept403 = false)
{
try {
$command->execute();
$exists = true;
} catch (AccessDeniedException $e) {
$exists = (bool) $accept403;
} catch (S3Exception $e) {
$exists = false;
if ($e->getResponse()->getStatusCode() >= 500) {
// @codeCoverageIgnoreStart
throw $e;
// @codeCoverageIgnoreEnd
}
}
return $exists;
}
示例2: 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) {
$request = $command->setClient($this)->prepare();
$this->dispatch('command.before_send', array('command' => $command));
// Set the state to new if the command was previously executed
if ($request->getState() !== RequestInterface::STATE_NEW) {
$request->setState(RequestInterface::STATE_NEW);
}
$request->send();
$this->dispatch('command.after_send', array('command' => $command));
return $command->getResult();
} elseif ($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();
} elseif (is_array($command)) {
return $this->execute(new CommandSet($command));
}
throw new InvalidArgumentException('Invalid command sent to ' . __METHOD__);
}