/**
  * creates a configuration from array
  *
  * array(
  *   'api' => '',  // optional
  *   'client_id' => '...',
  *   'client_secret' => '...',
  *   'site_token' => '',
  *   'cache_file' => '..',
  * )
  *
  * @param array $data
  *
  * @return ClientConfig
  * @throws ClientConfigurationException
  */
 public static function fromArray(array $data)
 {
     if (!array_key_exists('client_id', $data)) {
         throw new ClientConfigurationException('Configuration file has no client_id set');
     }
     if (!array_key_exists('client_secret', $data)) {
         throw new ClientConfigurationException('Configuration file has no client_secret set');
     }
     if (!array_key_exists('site_token', $data)) {
         throw new ClientConfigurationException('Configuration file has no site_token set');
     }
     $baseUrl = !array_key_exists('api', $data) ? null : $data['api'];
     $httpClientConfig = !array_key_exists('http_client', $data) ? array() : $data['http_client'];
     $clientConfig = new ClientConfig($data['client_id'], $data['client_secret'], $data['site_token'], $baseUrl, $httpClientConfig);
     if (array_key_exists('cache_file', $data)) {
         $clientConfig->setAccessTokenCacheFile($data['cache_file']);
     }
     return $clientConfig;
 }
示例#2
0
 /**
  * get all actions
  *
  * @param ClientCommand $command
  *
  * @return Response|CommandResponse|DecryptedCommandResponse|StatusResponse
  */
 public function send(ClientCommand $command)
 {
     $request = $this->client->createRequest($command->method(), $this->client->getBaseUrl() . $command->uri($this->cryptographyEngine), $this->headers($command->apiVersion(), $command->format(), $command->headers()), $command->body($this->cryptographyEngine), $this->config->getHttpClientConfig());
     try {
         $response = $request->send();
     } catch (ClientErrorResponseException $exception) {
         $response = $exception->getResponse();
     } catch (ServerErrorResponseException $exception) {
         $response = $exception->getResponse();
     }
     return $command->response($response, $this->cryptographyEngine);
 }