本文整理汇总了PHP中Guzzle\Service\Command\CommandInterface类的典型用法代码示例。如果您正苦于以下问题:PHP CommandInterface类的具体用法?PHP CommandInterface怎么用?PHP CommandInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: visit
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{
$this->fqname = $command->getName();
$query = array();
$this->customResolver($value, $param, $query, $param->getWireName());
$request->addPostFields($query);
}
示例2: fromCommand
/**
* Create a new model instance from a command.
*
* @param CommandInterface
* @return array
*/
public static function fromCommand(CommandInterface $command)
{
$file = new self();
$file->setParameters($command->getResponse()->json() + array('path' => $command['path']));
$file->finishUpload();
return $file->getParameters();
}
示例3: after
public function after(CommandInterface $command, RequestInterface $request)
{
$xml = null;
if (isset($this->data[$command])) {
$xml = $this->finishDocument($this->data[$command]);
unset($this->data[$command]);
} else {
$operation = $command->getOperation();
if ($operation->getData('xmlAllowEmpty')) {
$xmlWriter = $this->createRootElement($operation);
$xml = $this->finishDocument($xmlWriter);
}
}
if ($xml) {
if ($this->contentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->contentType);
}
$request->setBody($xml);
}
}
示例4: handleParsing
protected function handleParsing(CommandInterface $command, Response $response, $contentType)
{
$operation = $command->getOperation();
$type = $operation->getResponseType();
$model = null;
if ($type == OperationInterface::TYPE_MODEL) {
$model = $operation->getServiceDescription()->getModel($operation->getResponseClass());
} elseif ($type == OperationInterface::TYPE_CLASS) {
$responseClassInterface = __NAMESPACE__ . '\\ResponseClassInterface';
$className = $operation->getResponseClass();
if (!class_exists($className)) {
throw new ResponseClassException("{$className} does not exist");
} elseif (!method_exists($className, 'fromCommand')) {
throw new ResponseClassException("{$className} must implement {$responseClassInterface}");
}
return $className::fromCommand($command);
}
if (!$model) {
// Return basic processing if the responseType is not model or the model cannot be found
return parent::handleParsing($command, $response, $contentType);
} elseif ($command[AbstractCommand::RESPONSE_PROCESSING] != AbstractCommand::TYPE_MODEL) {
// Returns a model with no visiting if the command response processing is not model
return new Model(parent::handleParsing($command, $response, $contentType), $model);
} else {
return new Model($this->visitResult($model, $command, $response), $model);
}
}
示例5: runCommand
/**
* @param CommandInterface $command
* @return EncodingResponse
*/
protected function runCommand($command)
{
try {
return $command->getResult();
} catch (\Exception $e) {
throw new RuntimeException('Could not run encoding.com request.', 0, $e);
}
}
示例6: hook_amazons3_command_alter
/**
* Allows modules to alter an S3 command after it has been created.
*
* @param \Guzzle\Service\Command\CommandInterface $command
* The command that was created.
*/
function hook_amazons3_command_alter(\Guzzle\Service\Command\CommandInterface $command)
{
if ($command->getName('HeadObject')) {
$command->setOnComplete(function () {
watchdog('amazons3', 'HeadObject was called.');
});
}
}
示例7: 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);
}
}
}
示例8: build
/**
* Create a resource iterator
*
* @param CommandInterface $data Command used for building the iterator
* @param array $options Iterator options.
*
* @return ResourceIteratorInterface
*/
public function build($data, array $options = null)
{
if (!$data instanceof CommandInterface) {
throw new InvalidArgumentException('The first argument must be an ' . 'instance of CommandInterface');
}
// Determine the name of the class to load
$className = $this->baseNamespace . '\\' . Inflector::camel($data->getName()) . 'Iterator';
return new $className($data, $options);
}
示例9: getClassName
/**
* {@inheritdoc}
*/
protected function getClassName(CommandInterface $command)
{
// If it's a ListWidgets command, we can iterate over it
if (preg_match('/^List[A-Za-z]+/', $command->getName())) {
return $this->iteratorClassName;
}
// Otherwise, we don't know how to iterate over that command
return null;
}
示例10: createLinkCommand
/**
* {@inheritdoc}
*/
public function createLinkCommand(CommandInterface $command, Parameter $structure, array $data)
{
$this->validateLink($data);
$this->validateLinkStructure($structure);
$operation = $structure->getData('operation');
$pattern = $structure->getData('pattern');
$params = $this->parseHref($data['href'], $pattern);
return $command->getClient()->getCommand($operation, $params);
}
示例11: 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);
}
}
示例12: 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);
}
示例13: before
/**
* {@inheritdoc}
*/
public function before(CommandInterface $command, array &$result)
{
$json = $command->getResponse()->json();
// store links to use later
if (array_key_exists($this->getOutputFieldName(), $json)) {
$this->set($command, $this->getFieldName(), $json[$this->getOutputFieldName()]);
}
// create new array of links which visit() adds to
$result[$this->getOutputFieldName()] = array();
}
示例14: factory
/**
* {@inheritdoc}
*/
public function factory(CommandInterface $originalCommand, array $data)
{
$command = $this->newCommand();
// set up embedded command
$command->setClient($originalCommand->getClient());
$originalResponse = $originalCommand->getResponse();
$response = $this->createResponse($originalResponse, $data);
$command->setResponse($response);
return $command;
}
示例15: createPresignedUrl
private function createPresignedUrl(AwsClientInterface $client, CommandInterface $command)
{
// Create a temporary client used to generate the presigned URL
$newClient = Ec2Client::factory(array('region' => $command['SourceRegion'], 'signature' => 'v4', 'credentials' => $client->getCredentials()));
$preCommand = $newClient->getCommand('CopySnapshot', $command->toArray());
$preCommand['__internal'] = true;
/** @var \Guzzle\Http\Message\EntityEnclosingRequest $preRequest */
$preRequest = $preCommand->prepare();
return $newClient->getSignature()->createPresignedUrl(SignatureV4::convertPostToGet($preRequest), $newClient->getCredentials(), '+1 hour');
}