‪TYPO3CMS  10.4
Client.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 namespace ‪TYPO3\CMS\Core\Http;
19 
20 use GuzzleHttp\ClientInterface as GuzzleClientInterface;
21 use GuzzleHttp\Exception\ConnectException;
22 use GuzzleHttp\Exception\GuzzleException;
23 use GuzzleHttp\Exception\RequestException;
24 use GuzzleHttp\RequestOptions;
25 use Psr\Http\Client\ClientExceptionInterface;
26 use Psr\Http\Client\ClientInterface;
27 use Psr\Http\Client\NetworkExceptionInterface;
28 use Psr\Http\Client\RequestExceptionInterface;
29 use Psr\Http\Message\RequestInterface;
30 use Psr\Http\Message\ResponseInterface;
33 
41 class ‪Client implements ClientInterface
42 {
46  private ‪$guzzle;
47 
48  public function ‪__construct(GuzzleClientInterface ‪$guzzle)
49  {
50  $this->guzzle = ‪$guzzle;
51  }
52 
62  public function ‪sendRequest(RequestInterface $request): ResponseInterface
63  {
64  try {
65  return $this->guzzle->send($request, [
66  RequestOptions::HTTP_ERRORS => false,
67  RequestOptions::ALLOW_REDIRECTS => false,
68  ]);
69  } catch (ConnectException $e) {
70  throw new NetworkException($e->getMessage(), 1566909446, $e->getRequest(), $e);
71  } catch (RequestException $e) {
72  throw new Client\RequestException($e->getMessage(), 1566909447, $e->getRequest(), $e);
73  } catch (GuzzleException $e) {
74  throw new ClientException($e->getMessage(), 1566909448, $e);
75  }
76  }
77 }
‪TYPO3\CMS\Core\Http\Client\$guzzle
‪GuzzleClientInterface $guzzle
Definition: Client.php:45
‪TYPO3\CMS\Core\Http\Client
Definition: Client.php:42
‪TYPO3\CMS\Core\Http\Client\NetworkException
Definition: NetworkException.php:28
‪TYPO3\CMS\Core\Http\Client\ClientException
Definition: ClientException.php:28
‪TYPO3\CMS\Core\Http\Client\sendRequest
‪ResponseInterface sendRequest(RequestInterface $request)
Definition: Client.php:61
‪TYPO3\CMS\Core\Http\Client\__construct
‪__construct(GuzzleClientInterface $guzzle)
Definition: Client.php:47
‪TYPO3\CMS\Core\Http
Definition: AbstractApplication.php:18