Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
<?php
|
|
2 |
|
|
3 |
declare(strict_types=1); |
|
4 |
|
|
5 |
namespace Kreait\Firebase\Messaging; |
|
6 |
|
|
7 |
use GuzzleHttp\ClientInterface; |
|
8 |
use GuzzleHttp\Promise\PromiseInterface; |
|
9 |
use Kreait\Firebase\Exception\FirebaseException; |
|
10 |
use Kreait\Firebase\Exception\MessagingApiExceptionConverter; |
|
11 |
use Kreait\Firebase\Exception\MessagingException; |
|
12 |
use Kreait\Firebase\Http\WrappedGuzzleClient; |
|
13 |
use Psr\Http\Message\RequestInterface; |
|
14 |
use Psr\Http\Message\ResponseInterface; |
|
15 |
use Throwable; |
|
16 |
|
|
17 |
/**
|
|
18 |
* @internal
|
|
19 |
*/
|
|
20 |
class ApiClient implements ClientInterface |
|
21 |
{
|
|
22 |
use WrappedGuzzleClient; |
|
23 |
|
|
24 |
/** @var MessagingApiExceptionConverter */
|
|
25 |
private $errorHandler; |
|
26 |
|
|
27 |
/**
|
|
28 |
* @internal
|
|
29 |
*/
|
|
30 | 12 |
public function __construct(ClientInterface $client) |
31 |
{
|
|
32 | 12 |
$this->client = $client; |
33 | 12 |
$this->errorHandler = new MessagingApiExceptionConverter(); |
34 |
}
|
|
35 |
|
|
36 |
/**
|
|
37 |
* @param array<string, mixed> $options
|
|
38 |
*
|
|
39 |
* @throws MessagingException
|
|
40 |
* @throws FirebaseException
|
|
41 |
*/
|
|
42 | 12 |
public function send(RequestInterface $request, array $options = []): ResponseInterface |
43 |
{
|
|
44 |
try { |
|
45 | 12 |
return $this->client->send($request); |
46 | 12 |
} catch (Throwable $e) { |
47 | 12 |
throw $this->errorHandler->convertException($e); |
48 |
}
|
|
49 |
}
|
|
50 |
|
|
51 |
/**
|
|
52 |
* @param array<string, mixed> $options
|
|
53 |
*/
|
|
54 |
public function sendAsync(RequestInterface $request, array $options = []): PromiseInterface |
|
55 |
{
|
|
56 |
return $this->client->sendAsync($request, $options) |
|
57 |
->then(null, function (Throwable $e): void { |
|
58 |
throw $this->errorHandler->convertException($e); |
|
59 |
});
|
|
60 |
}
|
|
61 |
}
|
Read our documentation on viewing source code .