本文整理匯總了PHP中Guzzle\Service\Command\CommandInterface::setClient方法的典型用法代碼示例。如果您正苦於以下問題:PHP CommandInterface::setClient方法的具體用法?PHP CommandInterface::setClient怎麽用?PHP CommandInterface::setClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Guzzle\Service\Command\CommandInterface
的用法示例。
在下文中一共展示了CommandInterface::setClient方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: prepareCommand
protected function prepareCommand(CommandInterface $command)
{
$request = $command->setClient($this)->prepare();
$request->setState(RequestInterface::STATE_NEW);
$this->dispatch('command.before_send', array('command' => $command));
return $request;
}
示例2: prepareCommand
/**
* Prepare a command for sending and get the RequestInterface object created by the command
*
* @param CommandInterface $command Command to prepare
*
* @return RequestInterface
*/
protected function prepareCommand(CommandInterface $command)
{
// Set the client and prepare the command
$request = $command->setClient($this)->prepare();
// Set the state to new if the command was previously executed
$request->setState(RequestInterface::STATE_NEW);
$this->dispatch('command.before_send', array('command' => $command));
return $request;
}
示例3: 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__);
}