1
<?php
2

3
declare(strict_types=1);
4

5
namespace Kreait\Firebase\Messaging\Http\Request;
6

7
use GuzzleHttp\Psr7\Request;
8
use function GuzzleHttp\Psr7\stream_for;
9
use function GuzzleHttp\Psr7\uri_for;
10
use Kreait\Firebase\Http\WrappedPsr7Request;
11
use Kreait\Firebase\Messaging\Message;
12
use Psr\Http\Message\RequestInterface;
13

14
final class SendMessage implements RequestInterface
15
{
16
    use WrappedPsr7Request;
17

18 12
    public function __construct(string $projectId, Message $message)
19
    {
20 12
        $uri = uri_for('https://fcm.googleapis.com/v1/projects/'.$projectId.'/messages:send');
21 12
        $body = stream_for(\json_encode(['message' => $message]));
22
        $headers = [
23 12
            'Content-Type' => 'application/json; charset=UTF-8',
24 12
            'Content-Length' => $body->getSize(),
25
        ];
26

27 12
        $this->wrappedRequest = new Request('POST', $uri, $headers, $body);
28
    }
29
}

Read our documentation on viewing source code .

Loading