/**
  * Create service with name
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @param $name
  * @param $requestedName
  * @return HttpApi
  */
 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
 {
     $config = $this->getConfig($serviceLocator)[$requestedName];
     $httpClient = isset($config['http_client']) && $serviceLocator->has($config['http_client']) ? $serviceLocator->get($config['http_client']) : null;
     $baseRequest = isset($config['base_request']) && $serviceLocator->has($config['base_request']) ? $serviceLocator->get($config['base_request']) : null;
     $api = new HttpApi($httpClient, $baseRequest);
     // Array of int code valid
     if (isset($config['valid_status_code']) && is_array($config['valid_status_code'])) {
         $api->setValidStatusCodes($config['valid_status_code']);
     }
     // string json/xml
     if (isset($config['request_format'])) {
         $api->setRequestFormat($config['request_format']);
     }
     // Profiler
     if (isset($config['profiler']) && $serviceLocator->has($config['profiler'])) {
         $api->setProfiler($serviceLocator->get($config['profiler']));
     }
     return $api;
 }
Пример #2
0
 public function testGetSetValidStatusCodes()
 {
     $this->assertSame($this->httpApi, $this->httpApi->setValidStatusCodes([200, 201]));
     $this->assertCount(2, $this->httpApi->getValidStatusCodes());
 }