Пример #1
0
 protected function sendRequest(Operation $operation, array $userValues = [], $async = false)
 {
     $uri = uri_template($operation->getPath(), $userValues);
     $options = RequestSerializer::serializeOptions($operation, $userValues);
     $method = $async ? 'requestAsync' : 'request';
     return $this->client->{$method}($operation->getMethod(), $uri, $options);
 }
Пример #2
0
 /**
  * @param CommandInterface $command
  *
  * @return RequestInterface
  */
 public function commandToRequestTransformer(CommandInterface $command)
 {
     $name = $command->getName();
     if (!isset($this->api[$name])) {
         throw new CommandException('Command not found', $command);
     }
     $action = $this->api[$name];
     $prefix = '';
     if (isset($action['public']) && $command->hasParam('public')) {
         $prefix = '/public';
     }
     $prefixes = ['system' => '/systems/{system}', 'issuer' => '/issuers/{issuer}', 'program' => '/programs/{program}'];
     if (isset($action['admin_contexts'])) {
         $prefix .= implode('', array_intersect_key($prefixes, array_flip($action['admin_contexts']), array_merge($command->toArray(), $this->adminContext)));
     }
     $path = GuzzleHttp\uri_template($prefix . $action['path'], array_merge($command->toArray(), $this->adminContext));
     $headers = [];
     $body = null;
     if ($command->hasParam('body')) {
         $headers = ['Content-Type' => 'application/json'];
         $body = GuzzleHttp\json_encode($command['body']);
     }
     if ($command->hasParam('query')) {
         $path .= '?' . Psr7\build_query($command['query']);
     }
     return new Psr7\Request($action['method'], $path, $headers, $body);
 }