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); }
private function addMd5(CommandInterface $command) { $request = $command->getRequest(); $body = $request->getBody(); if ($body && $body->getSize() > 0) { if (false !== ($md5 = $body->getContentMd5(true, true))) { $request->setHeader('Content-MD5', $md5); } } }
public function parse(CommandInterface $command) { $response = $command->getRequest()->getResponse(); // Account for hard coded content-type values specified in service descriptions if ($contentType = $command['command.expects']) { $response->setHeader('Content-Type', $contentType); } else { $contentType = (string) $response->getHeader('Content-Type'); } return $this->handleParsing($command, $response, $contentType); }
public function getClassName(CommandInterface $command) { $className = $command->getName(); if (isset($this->map[$className])) { return $this->map[$className]; } elseif (isset($this->map['*'])) { // If a wildcard was added, then always use that return $this->map['*']; } return null; }
protected function getClassName(CommandInterface $command) { $iteratorName = $this->inflector->camel($command->getName()) . 'Iterator'; // Determine the name of the class to load foreach ($this->namespaces as $namespace) { $potentialClassName = $namespace . '\\' . $iteratorName; if (class_exists($potentialClassName)) { return $potentialClassName; } } return false; }
public function build(CommandInterface $command, array $options = array()) { // Get the configuration data for the command $commandName = $command->getName(); $commandSupported = isset($this->config[$commandName]); $options = $this->translateLegacyConfigOptions($options); $options += $commandSupported ? $this->config[$commandName] : array(); // Instantiate the iterator using the primary factory (if one was provided) if ($this->primaryIteratorFactory && $this->primaryIteratorFactory->canBuild($command)) { $iterator = $this->primaryIteratorFactory->build($command, $options); } elseif (!$commandSupported) { throw new InvalidArgumentException("Iterator was not found for {$commandName}."); } else { // Instantiate a generic AWS resource iterator $iterator = new AwsResourceIterator($command, $options); } return $iterator; }
public function after(CommandInterface $command, RequestInterface $request) { $xml = null; // If data was found that needs to be serialized, then do so if (isset($this->data[$command])) { $xml = $this->finishDocument($this->data[$command]); unset($this->data[$command]); } else { // Check if XML should always be sent for the command $operation = $command->getOperation(); if ($operation->getData('xmlAllowEmpty')) { $xmlWriter = $this->createRootElement($operation); $xml = $this->finishDocument($xmlWriter); } } if ($xml) { // Don't overwrite the Content-Type if one is set if ($this->contentType && !$request->hasHeader('Content-Type')) { $request->setHeader('Content-Type', $this->contentType); } $request->setBody($xml); } }
/** * Parse a class object * * @param CommandInterface $command Command to parse into an object * * @return mixed * @throws ResponseClassException */ protected function parseClass(CommandInterface $command) { // Emit the operation.parse_class event. If a listener injects a 'result' property, then that will be the result $event = new CreateResponseClassEvent(array('command' => $command)); $command->getClient()->getEventDispatcher()->dispatch('command.parse_response', $event); if ($result = $event->getResult()) { return $result; } $className = $command->getOperation()->getResponseClass(); if (!method_exists($className, 'fromCommand')) { throw new ResponseClassException("{$className} must exist and implement a static fromCommand() method"); } return $className::fromCommand($command); }
/** * 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()); }
/** * Create a request for the command and operation * * @param CommandInterface $command Command to create a request for * * @return RequestInterface */ protected function createRequest(CommandInterface $command) { $operation = $command->getOperation(); $client = $command->getClient(); $options = $command[AbstractCommand::REQUEST_OPTIONS] ?: array(); // If the command does not specify a template, then assume the base URL of the client if (!($uri = $operation->getUri())) { return $client->createRequest($operation->getHttpMethod(), $client->getBaseUrl(), null, null, $options); } // Get the path values and use the client config settings $variables = array(); foreach ($operation->getParams() as $name => $arg) { if ($arg->getLocation() == 'uri') { if (isset($command[$name])) { $variables[$name] = $arg->filter($command[$name]); if (!is_array($variables[$name])) { $variables[$name] = (string) $variables[$name]; } } } } return $client->createRequest($operation->getHttpMethod(), array($uri, $variables), null, null, $options); }
private function validateScheme(CommandInterface $command) { if ($command->getClient()->getConfig('scheme') !== 'https') { throw new RuntimeException('You must configure your S3 client to ' . 'use HTTPS in order to use the SSE-C features.'); } }
public function before(CommandInterface $command, array &$result) { // Ensure that the result of the command is always rooted with the parsed JSON data $result = $command->getResponse()->json(); }
/** * Process the response of the DeleteMultipleObjects request * * @paramCommandInterface $command Command executed */ protected function processResponse(CommandInterface $command) { $result = $command->getResult(); // Ensure that the objects were deleted successfully if (!empty($result['Errors'])) { $errors = $result['Errors']; throw new DeleteMultipleObjectsException($errors); } }
/** * 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; }
/** * 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; }
/** * Serialize and sign a command, returning a request object * * @param CommandInterface $command Command to sign * * @return RequestInterface */ protected function getSignedRequest($command) { $request = $command->prepare(); $request->dispatch('request.before_send', array('request' => $request)); return $request; }