vendor/nellapp/sdk-bundle/src/ApiClientInterApp/Proxy/AbstractProxyClient.php line 23

Open in your IDE?
  1. <?php
  2. namespace Nellapp\Bundle\SDKBundle\ApiClientInterApp\Proxy;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  5. use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
  6. use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
  7. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  8. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  9. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  10. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  11. use Symfony\Contracts\HttpClient\ResponseInterface;
  12. abstract class AbstractProxyClient implements ProxyClientInterface
  13. {
  14.     /**
  15.      * @throws RedirectionExceptionInterface
  16.      * @throws ClientExceptionInterface
  17.      * @throws TransportExceptionInterface
  18.      * @throws ServerExceptionInterface
  19.      */
  20.     public function get(string $appstring $path, array $query = [], array $headers = []): Response
  21.     {
  22.         $response $this->doGet($app$path$query$headers);
  23.         if (401 === $response->getStatusCode()) {
  24.             throw new UnauthorizedHttpException('');
  25.         }
  26.         if (404 === $response->getStatusCode()) {
  27.             throw new NotFoundHttpException();
  28.         }
  29.         $statusCode $response->getStatusCode();
  30.         if ($statusCode >= 500) {
  31.             throw new ServiceUnavailableHttpException();
  32.         }
  33.         $headers array_filter($response->getHeaders(false), function (string $key) {
  34.             return in_array(strtolower($key), [
  35.                 'content-type',
  36.             ]);
  37.         }, ARRAY_FILTER_USE_KEY);
  38.         return new Response(
  39.             $response->getContent(),
  40.             $response->getStatusCode(),
  41.             $headers
  42.         );
  43.     }
  44.     abstract public function doGet(string $appstring $path, array $query = [], array $headers = []): ?ResponseInterface;
  45. }