Laravel version update
Laravel version update
This commit is contained in:
163
vendor/brozot/laravel-fcm/src/Sender/FCMGroup.php
vendored
163
vendor/brozot/laravel-fcm/src/Sender/FCMGroup.php
vendored
@@ -1,99 +1,94 @@
|
||||
<?php namespace LaravelFCM\Sender;
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Sender;
|
||||
|
||||
use LaravelFCM\Request\GroupRequest;
|
||||
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Class FCMGroup
|
||||
*
|
||||
* @package LaravelFCM\Sender
|
||||
* Class FCMGroup.
|
||||
*/
|
||||
class FCMGroup extends HTTPSender {
|
||||
|
||||
const CREATE = "create";
|
||||
const ADD = "add";
|
||||
const REMOVE = "remove";
|
||||
class FCMGroup extends HTTPSender
|
||||
{
|
||||
const CREATE = 'create';
|
||||
const ADD = 'add';
|
||||
const REMOVE = 'remove';
|
||||
|
||||
/**
|
||||
* Create a group
|
||||
*
|
||||
* @param $notificationKeyName
|
||||
* @param array $registrationIds
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function createGroup($notificationKeyName, array $registrationIds)
|
||||
{
|
||||
$request = new GroupRequest(self::CREATE, $notificationKeyName, null, $registrationIds);
|
||||
|
||||
$response = $this->client->post($this->url, $request->build());
|
||||
/**
|
||||
* Create a group.
|
||||
*
|
||||
* @param $notificationKeyName
|
||||
* @param array $registrationIds
|
||||
*
|
||||
* @return null|string notification_key
|
||||
*/
|
||||
public function createGroup($notificationKeyName, array $registrationIds)
|
||||
{
|
||||
$request = new GroupRequest(self::CREATE, $notificationKeyName, null, $registrationIds);
|
||||
|
||||
return $this->getNotificationToken($response);
|
||||
}
|
||||
$response = $this->client->request('post', $this->url, $request->build());
|
||||
|
||||
/**
|
||||
* add registrationId to a existing group
|
||||
*
|
||||
* @param $notificationKeyName
|
||||
* @param $notificationKey
|
||||
* @param array $registrationIds registrationIds to add
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function addToGroup($notificationKeyName, $notificationKey, array $registrationIds)
|
||||
{
|
||||
$request = new GroupRequest(self::ADD, $notificationKeyName, $notificationKey, $registrationIds);
|
||||
$response = $this->client->post($this->url, $request->build());
|
||||
return $this->getNotificationToken($response);
|
||||
}
|
||||
|
||||
return $this->getNotificationToken($response);
|
||||
}
|
||||
/**
|
||||
* add registrationId to a existing group.
|
||||
*
|
||||
* @param $notificationKeyName
|
||||
* @param $notificationKey
|
||||
* @param array $registrationIds registrationIds to add
|
||||
* @return null|string notification_key
|
||||
*/
|
||||
public function addToGroup($notificationKeyName, $notificationKey, array $registrationIds)
|
||||
{
|
||||
$request = new GroupRequest(self::ADD, $notificationKeyName, $notificationKey, $registrationIds);
|
||||
$response = $this->client->request('post', $this->url, $request->build());
|
||||
|
||||
/**
|
||||
* remove registrationId to a existing group
|
||||
*
|
||||
* >Note: if you remove all registrationIds the group is automatically deleted
|
||||
*
|
||||
* @param $notificationKeyName
|
||||
* @param $notificationKey
|
||||
* @param array $registeredIds registrationIds to remove
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function removeFromGroup($notificationKeyName, $notificationKey, array $registeredIds)
|
||||
{
|
||||
$request = new GroupRequest(self::REMOVE, $notificationKeyName, $notificationKey, $registeredIds);
|
||||
$response = $this->client->post($this->url, $request->build());
|
||||
return $this->getNotificationToken($response);
|
||||
}
|
||||
|
||||
return $this->getNotificationToken($response);
|
||||
}
|
||||
/**
|
||||
* remove registrationId to a existing group.
|
||||
*
|
||||
* >Note: if you remove all registrationIds the group is automatically deleted
|
||||
*
|
||||
* @param $notificationKeyName
|
||||
* @param $notificationKey
|
||||
* @param array $registeredIds registrationIds to remove
|
||||
* @return null|string notification_key
|
||||
*/
|
||||
public function removeFromGroup($notificationKeyName, $notificationKey, array $registeredIds)
|
||||
{
|
||||
$request = new GroupRequest(self::REMOVE, $notificationKeyName, $notificationKey, $registeredIds);
|
||||
$response = $this->client->request('post', $this->url, $request->build());
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param GuzzleResponse $response
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function getNotificationToken(GuzzleResponse $response)
|
||||
{
|
||||
if ($this->isValidResponse($response)) {
|
||||
return null;
|
||||
}
|
||||
return $this->getNotificationToken($response);
|
||||
}
|
||||
|
||||
$json = json_decode($response->getBody(), true);
|
||||
return $json['notification_key'];
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
* @return null|string notification_key
|
||||
*/
|
||||
private function getNotificationToken(ResponseInterface $response)
|
||||
{
|
||||
if (! $this->isValidResponse($response)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param $response
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidResponse(GuzzleResponse $response)
|
||||
{
|
||||
return $response->getReasonPhrase() != 'OK' || $response->getStatusCode() != 200;
|
||||
}
|
||||
$json = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
}
|
||||
return $json['notification_key'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidResponse(ResponseInterface $response)
|
||||
{
|
||||
return $response->getStatusCode() === 200;
|
||||
}
|
||||
}
|
||||
|
||||
187
vendor/brozot/laravel-fcm/src/Sender/FCMSender.php
vendored
187
vendor/brozot/laravel-fcm/src/Sender/FCMSender.php
vendored
@@ -1,4 +1,6 @@
|
||||
<?php namespace LaravelFCM\Sender;
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Sender;
|
||||
|
||||
use LaravelFCM\Message\Topics;
|
||||
use LaravelFCM\Request\Request;
|
||||
@@ -11,113 +13,106 @@ use LaravelFCM\Response\DownstreamResponse;
|
||||
use LaravelFCM\Message\PayloadNotification;
|
||||
|
||||
/**
|
||||
* Class FCMSender
|
||||
*
|
||||
* @package LaravelFCM\Sender
|
||||
* Class FCMSender.
|
||||
*/
|
||||
class FCMSender extends HTTPSender {
|
||||
class FCMSender extends HTTPSender
|
||||
{
|
||||
const MAX_TOKEN_PER_REQUEST = 1000;
|
||||
|
||||
const MAX_TOKEN_PER_REQUEST = 1000;
|
||||
/**
|
||||
* send a downstream message to.
|
||||
*
|
||||
* - a unique device with is registration Token
|
||||
* - or to multiples devices with an array of registrationIds
|
||||
*
|
||||
* @param string|array $to
|
||||
* @param Options|null $options
|
||||
* @param PayloadNotification|null $notification
|
||||
* @param PayloadData|null $data
|
||||
*
|
||||
* @return DownstreamResponse|null
|
||||
*/
|
||||
public function sendTo($to, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
$response = null;
|
||||
|
||||
/**
|
||||
* send a downstream message to
|
||||
*
|
||||
* - a unique device with is registration Token
|
||||
* - or to multiples devices with an array of registrationIds
|
||||
*
|
||||
* @param String|array $to
|
||||
* @param Options|null $options
|
||||
* @param PayloadNotification|null $notification
|
||||
* @param PayloadData|null $data
|
||||
*
|
||||
* @return DownstreamResponse|null
|
||||
*
|
||||
*/
|
||||
public function sendTo($to, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
$response = null;
|
||||
if (is_array($to) && !empty($to)) {
|
||||
$partialTokens = array_chunk($to, self::MAX_TOKEN_PER_REQUEST, false);
|
||||
foreach ($partialTokens as $tokens) {
|
||||
$request = new Request($tokens, $options, $notification, $data);
|
||||
|
||||
if (is_array($to) && !empty($to)) {
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
$partialTokens = array_chunk($to, self::MAX_TOKEN_PER_REQUEST, false);
|
||||
foreach ($partialTokens as $tokens) {
|
||||
$request = new Request($tokens, $options, $notification, $data);
|
||||
$responsePartial = new DownstreamResponse($responseGuzzle, $tokens);
|
||||
if (!$response) {
|
||||
$response = $responsePartial;
|
||||
} else {
|
||||
$response->merge($responsePartial);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$request = new Request($to, $options, $notification, $data);
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
$responseGuzzle = $this->post($request);
|
||||
$response = new DownstreamResponse($responseGuzzle, $to);
|
||||
}
|
||||
|
||||
$responsePartial = new DownstreamResponse($responseGuzzle, $tokens);
|
||||
if (!$response) {
|
||||
$response = $responsePartial;
|
||||
}
|
||||
else {
|
||||
$response->merge($responsePartial);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$request = new Request($to, $options, $notification, $data);
|
||||
$responseGuzzle = $this->post($request);
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response = new DownstreamResponse($responseGuzzle, $to);
|
||||
}
|
||||
/**
|
||||
* Send a message to a group of devices identified with them notification key.
|
||||
*
|
||||
* @param $notificationKey
|
||||
* @param Options|null $options
|
||||
* @param PayloadNotification|null $notification
|
||||
* @param PayloadData|null $data
|
||||
*
|
||||
* @return GroupResponse
|
||||
*/
|
||||
public function sendToGroup($notificationKey, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
$request = new Request($notificationKey, $options, $notification, $data);
|
||||
|
||||
return $response;
|
||||
}
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
/**
|
||||
* Send a message to a group of devices identified with them notification key
|
||||
*
|
||||
* @param $notificationKey
|
||||
* @param Options|null $options
|
||||
* @param PayloadNotification|null $notification
|
||||
* @param PayloadData|null $data
|
||||
*
|
||||
* @return GroupResponse
|
||||
*/
|
||||
public function sendToGroup($notificationKey, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
$request = new Request($notificationKey, $options, $notification, $data);
|
||||
return new GroupResponse($responseGuzzle, $notificationKey);
|
||||
}
|
||||
|
||||
$responseGuzzle = $this->post($request);
|
||||
/**
|
||||
* Send message devices registered at a or more topics.
|
||||
*
|
||||
* @param Topics $topics
|
||||
* @param Options|null $options
|
||||
* @param PayloadNotification|null $notification
|
||||
* @param PayloadData|null $data
|
||||
*
|
||||
* @return TopicResponse
|
||||
*/
|
||||
public function sendToTopic(Topics $topics, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
$request = new Request(null, $options, $notification, $data, $topics);
|
||||
|
||||
return new GroupResponse($responseGuzzle, $notificationKey);
|
||||
}
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
/**
|
||||
* Send message devices registered at a or more topics
|
||||
*
|
||||
* @param Topics $topics
|
||||
* @param Options|null $options
|
||||
* @param PayloadNotification|null $notification
|
||||
* @param PayloadData|null $data
|
||||
*
|
||||
* @return TopicResponse
|
||||
*/
|
||||
public function sendToTopic(Topics $topics, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
$request = new Request(null, $options, $notification, $data, $topics);
|
||||
return new TopicResponse($responseGuzzle, $topics);
|
||||
}
|
||||
|
||||
$responseGuzzle = $this->post($request);
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param \LaravelFCM\Request\Request $request
|
||||
*
|
||||
* @return null|\Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
private function post($request)
|
||||
{
|
||||
try {
|
||||
$responseGuzzle = $this->client->request('post', $this->url, $request->build());
|
||||
} catch (ClientException $e) {
|
||||
$responseGuzzle = $e->getResponse();
|
||||
}
|
||||
|
||||
return new TopicResponse($responseGuzzle, $topics);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param $request
|
||||
*
|
||||
* @return null|\Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
private function post($request)
|
||||
{
|
||||
try {
|
||||
$responseGuzzle = $this->client->post($this->url, $request->build());
|
||||
}
|
||||
catch (ClientException $e) {
|
||||
$responseGuzzle = $e->getResponse();
|
||||
}
|
||||
|
||||
return $responseGuzzle;
|
||||
}
|
||||
}
|
||||
return $responseGuzzle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
<?php namespace LaravelFCM\Sender;
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Sender;
|
||||
|
||||
use GuzzleHttp\ClientInterface;
|
||||
|
||||
/**
|
||||
* Class BaseSender
|
||||
*
|
||||
* @package LaravelFCM\Sender
|
||||
* Class BaseSender.
|
||||
*/
|
||||
abstract class HTTPSender {
|
||||
abstract class HTTPSender
|
||||
{
|
||||
/**
|
||||
* The client used to send messages.
|
||||
*
|
||||
* @var \GuzzleHttp\ClientInterface
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* The client used to send messages.
|
||||
*
|
||||
* @var GuzzleHttp\ClientInterface
|
||||
*/
|
||||
protected $client;
|
||||
/**
|
||||
* The URL entry point.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* The URL entry point.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* Initializes a new sender object.
|
||||
*
|
||||
* @param GuzzleHttp\ClientInterface $client
|
||||
* @param string $url
|
||||
*/
|
||||
public function __construct(ClientInterface $client, $url)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Initializes a new sender object.
|
||||
*
|
||||
* @param \GuzzleHttp\ClientInterface $client
|
||||
* @param string $url
|
||||
*/
|
||||
public function __construct(ClientInterface $client, $url)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->url = $url;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user