/**
  * {@inheritdoc}
  */
 protected function handleParsing(AbstractCommand $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 (!is_subclass_of($className, $responseClassInterface)) {
             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->get(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);
     }
 }
 public function setUp()
 {
     $this->serializer = DefaultRequestSerializer::getInstance();
     $this->client = new Client('http://foo.com/baz');
     $this->operation = new Operation(array('httpMethod' => 'POST'));
     $this->command = $this->getMockBuilder('Guzzle\\Service\\Command\\AbstractCommand')->setConstructorArgs(array(array(), $this->operation))->getMockForAbstractClass();
     $this->command->setClient($this->client);
 }
示例#3
0
 /**
  * Factory that creates a PutRequest from a PutItem command
  *
  * @param AbstractCommand $command The command to create the request from
  *
  * @return PutRequest
  *
  * @throws InvalidArgumentException if the command is not a PutItem command
  */
 public static function fromCommand(AbstractCommand $command)
 {
     if ($command->getName() !== 'PutItem') {
         throw new InvalidArgumentException();
     }
     // Get relevant data for a PutRequest
     $table = $command->get('TableName');
     $item = $command->get('Item');
     // Return an instantiated PutRequest object
     return new PutRequest($item, $table);
 }
 /**
  * Factory that creates a DeleteRequest from a DeleteItem command
  *
  * @param AbstractCommand $command The command to create the request from
  *
  * @return PutRequest
  *
  * @throws InvalidArgumentException if the command is not a DeleteItem command
  */
 public static function fromCommand(AbstractCommand $command)
 {
     if ($command->getName() !== 'DeleteItem') {
         throw new InvalidArgumentException();
     }
     // Get relevant data for a DeleteRequest
     $table = $command->get('TableName');
     $key = $command->get('Key');
     // Return an instantiated DeleteRequest object
     return new DeleteRequest($key, $table);
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 protected function handleParsing(AbstractCommand $command, Response $response, $contentType)
 {
     $operation = $command->getOperation();
     $model = $operation->getResponseType() == OperationInterface::TYPE_MODEL ? $operation->getServiceDescription()->getModel($operation->getResponseClass()) : null;
     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->get(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);
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function process()
 {
     parent::process();
     // Execute as normally if includeChildren is false
     if (!$this->get('includeChildren') || null === $this->get('includeChildren')) {
         return;
     }
     $results = $this->getResult();
     $labelId = $this->get('labelId');
     $labelsChildren = $this->getClient()->getCommand('GetLabelsChildren', array('labelId' => $labelId))->execute();
     if (count($labelsChildren['items']) > 0) {
         // Loop through all of a label's children and retrieve any child assets
         foreach ($labelsChildren['items'] as $childKey => $childLabel) {
             $childAssets = $this->getAssetsByLabelId($childLabel['id']);
             // Make pagination available for some of the child label's
             if (null !== $childAssets['next_page']) {
                 $results['next_page'][$childLabel['id']] = $childAssets['next_page'];
             }
             // Append child's assets to original result array
             foreach ($childAssets['items'] as $childAsset) {
                 $results['items'][] = $childAsset;
             }
         }
     }
     $this->setResult($results);
 }
示例#7
0
 public function execute()
 {
     $result = parent::execute();
     $config = $this->client->getConfig();
     foreach ($result as $key => $value) {
         $config->set('hg.' . $key, $value);
     }
     return $result;
 }
 /**
  * Returns a SimpleXMLElement
  *
  * @return \SimpleXMLElement
  */
 public function getResult()
 {
     return parent::getResult();
 }
示例#9
0
文件: Acp.php 项目: loulancn/core
 /**
  * Applies grant headers to a command's parameters
  *
  * @param AbstractCommand $command Command to be updated
  *
  * @return $this
  */
 public function updateCommand(AbstractCommand $command)
 {
     $parameters = array();
     foreach ($this->grants as $grant) {
         /** @var $grant Grant */
         $parameters = array_merge_recursive($parameters, $grant->getParameterArray());
     }
     foreach ($parameters as $name => $values) {
         $command->set($name, implode(', ', (array) $values));
     }
     return $this;
 }
示例#10
0
 /**
  * Determines whether a command's response type is a model
  *
  * @param Guzzle\Service\Command\AbstractCommand $command
  *
  * @return boolean
  */
 public function responseTypeIsModel(AbstractCommand $command)
 {
     $operation = $command->getOperation();
     $processing = $command->get(AbstractCommand::RESPONSE_PROCESSING);
     $description = $operation->getServiceDescription();
     return $operation->getResponseType() == OperationInterface::TYPE_MODEL && $description->hasModel($operation->getResponseClass()) && $processing == AbstractCommand::TYPE_MODEL;
 }
 /**
  * {@inheritdoc}
  */
 protected function process()
 {
     parent::process();
     if (strpos($this->getResponse()->getBody(true), '<?xml') !== false) {
         $body = $this->getResponse()->getBody(true);
         $body = preg_replace('# xmlns=[^ >]*#', '', $body);
         $this->result = new \SimpleXMLElement($body);
     }
     if ($this->result instanceof \SimpleXMLElement) {
         // @codeCoverageIgnoreStart
         if (empty($this->resultNode)) {
             $resultNode = $this->action . 'Result';
         } else {
             $resultNode = $this->resultNode;
         }
         // @codeCoverageIgnoreEnd
         if ($resultNode != '.') {
             $this->result = $this->result->{$resultNode};
         }
         // Iterable result
         if ($this instanceof AbstractIterableMwsCommand || $this instanceof AbstractIterableMwsOrderCommand) {
             $nextCommand = Inflector::snake($this->action . 'ByNextToken');
             $records = $this->result;
             if ($this->recordPath) {
                 $records = $this->result->xpath($this->recordPath);
             }
             // Get next token unless HasNext property is set to false
             if (!isset($this->result->NextToken)) {
                 $nextToken = null;
             } elseif (!empty($this->result->HasNext)) {
                 if ($this->result->HasNext == 'false') {
                     $nextToken = null;
                 }
             }
             $this->result = new ResultIterator($this->getClient(), array('next_token' => $nextToken, 'next_command' => $nextCommand, 'resources' => $records, 'result_node' => $resultNode, 'record_path' => $this->recordPath));
         } else {
             if (!empty($this->recordPath)) {
                 $this->result = $this->result->xpath($this->recordPath);
             }
         }
     } else {
         if ($this->result->getContentType() == 'application/octet-stream') {
             // Get CSV data array
             $this->result = new CsvReport($this->getResponse()->getBody(true));
         }
     }
 }