upgraded dependencies

This commit is contained in:
RafficMohammed
2023-01-08 01:59:16 +05:30
parent 51056e3aad
commit f9ae387337
6895 changed files with 133617 additions and 178680 deletions

View File

@@ -1,12 +0,0 @@
<?php
namespace LaravelFCM\Message\Exceptions;
use Exception;
/**
* Class InvalidOptionsException.
*/
class InvalidOptionsException extends Exception
{
}

View File

@@ -1,12 +0,0 @@
<?php
namespace LaravelFCM\Message\Exceptions;
use Exception;
/**
* Class NoTopicProvidedException.
*/
class NoTopicProvidedException extends Exception
{
}

View File

@@ -1,110 +0,0 @@
<?php
namespace LaravelFCM\Message;
use Illuminate\Contracts\Support\Arrayable;
/**
* Class Options.
*/
class Options implements Arrayable
{
/**
* @internal
*
* @var null|string
*/
protected $collapseKey;
/**
* @internal
*
* @var null|string
*/
protected $priority;
/**
* @internal
*
* @var bool
*/
protected $contentAvailable;
/**
* @internal
*
* @var bool
*/
protected $isMutableContent = false;
/**
* @internal
*
* @var bool
*/
protected $delayWhileIdle;
/**
* @internal
*
* @var int|null
*/
protected $timeToLive;
/**
* @internal
*
* @var null|string
*/
protected $restrictedPackageName;
/**
* @internal
*
* @var bool
*/
protected $isDryRun = false;
/**
* Options constructor.
*
* @param OptionsBuilder $builder
*/
public function __construct(OptionsBuilder $builder)
{
$this->collapseKey = $builder->getCollapseKey();
$this->priority = $builder->getPriority();
$this->contentAvailable = $builder->isContentAvailable();
$this->isMutableContent = $builder->isMutableContent();
$this->delayWhileIdle = $builder->isDelayWhileIdle();
$this->timeToLive = $builder->getTimeToLive();
$this->restrictedPackageName = $builder->getRestrictedPackageName();
$this->isDryRun = $builder->isDryRun();
}
/**
* Transform Option to array.
*
* @return array
*/
public function toArray()
{
$contentAvailable = $this->contentAvailable ? true : null;
$mutableContent = $this->isMutableContent ? true : null;
$delayWhileIdle = $this->delayWhileIdle ? true : null;
$dryRun = $this->isDryRun ? true : null;
$options = [
'collapse_key' => $this->collapseKey,
'priority' => $this->priority,
'content_available' => $contentAvailable,
'mutable_content' => $mutableContent,
'delay_while_idle' => $delayWhileIdle,
'time_to_live' => $this->timeToLive,
'restricted_package_name' => $this->restrictedPackageName,
'dry_run' => $dryRun,
];
return array_filter($options);
}
}

View File

@@ -1,336 +0,0 @@
<?php
namespace LaravelFCM\Message;
use LaravelFCM\Message\Exceptions\InvalidOptionsException;
use ReflectionClass;
/**
* Builder for creation of options used by FCM.
*
* Class OptionsBuilder
*
* @link http://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
*/
class OptionsBuilder
{
/**
* @internal
*
* @var string
*/
protected $collapseKey;
/**
* @internal
*
* @var string
*/
protected $priority;
/**
* @internal
*
* @var bool
*/
protected $contentAvailable = false;
/**
* @internal
* @var bool
*/
protected $mutableContent;
/**
* @internal
*
* @var bool
*/
protected $delayWhileIdle = false;
/**
* @internal
*
* @var string
*/
protected $timeToLive;
/**
* @internal
*
* @var string
*/
protected $restrictedPackageName;
/**
* @internal
*
* @var bool
*/
protected $dryRun = false;
/**
* This parameter identifies a group of messages
* A maximum of 4 different collapse keys is allowed at any given time.
*
* @param string $collapseKey
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setCollapseKey($collapseKey)
{
$this->collapseKey = $collapseKey;
return $this;
}
/**
* Sets the priority of the message. Valid values are "normal" and "high."
* By default, messages are sent with normal priority.
*
* @param string $priority
*
* @return \LaravelFCM\Message\OptionsBuilder
*
* @throws InvalidOptionsException
* @throws \ReflectionException
*/
public function setPriority($priority)
{
if (!OptionsPriorities::isValid($priority)) {
throw new InvalidOptionsException('priority is not valid, please refer to the documentation or use the constants of the class "OptionsPriorities"');
}
$this->priority = $priority;
return $this;
}
/**
* support only Android and Ios.
*
* An inactive client app is awoken.
* On iOS, use this field to represent content-available in the APNS payload.
* On Android, data messages wake the app by default.
* On Chrome, currently not supported.
*
* @param bool $contentAvailable
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setContentAvailable($contentAvailable)
{
$this->contentAvailable = $contentAvailable;
return $this;
}
/**
* support iOS 10+
*
* When a notification is sent and this is set to true,
* the content of the notification can be modified before it is displayed.
*
* @param String $isMutableContent
* @return OptionsBuilder
*/
public function setMutableContent($isMutableContent)
{
$this->mutableContent = $isMutableContent;
return $this;
}
/**
* When this parameter is set to true, it indicates that the message should not be sent until the device becomes active.
*
* @param bool $delayWhileIdle
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setDelayWhileIdle($delayWhileIdle)
{
$this->delayWhileIdle = $delayWhileIdle;
return $this;
}
/**
* This parameter specifies how long the message should be kept in FCM storage if the device is offline.
*
* @param int $timeToLive (in second) min:0 max:2419200
*
* @return \LaravelFCM\Message\OptionsBuilder
*
* @throws InvalidOptionsException
*/
public function setTimeToLive($timeToLive)
{
if ($timeToLive < 0 || $timeToLive > 2419200) {
throw new InvalidOptionsException("time to live must be between 0 and 2419200, current value is: {$timeToLive}");
}
$this->timeToLive = $timeToLive;
return $this;
}
/**
* This parameter specifies the package name of the application where the registration tokens must match in order to receive the message.
*
* @param string $restrictedPackageName
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setRestrictedPackageName($restrictedPackageName)
{
$this->restrictedPackageName = $restrictedPackageName;
return $this;
}
/**
* This parameter, when set to true, allows developers to test a request without actually sending a message.
* It should only be used for the development.
*
* @param bool $isDryRun
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setDryRun($isDryRun)
{
$this->dryRun = $isDryRun;
return $this;
}
/**
* Get the collapseKey.
*
* @return null|string
*/
public function getCollapseKey()
{
return $this->collapseKey;
}
/**
* Get the priority.
*
* @return null|string
*/
public function getPriority()
{
return $this->priority;
}
/**
* is content available.
*
* @return bool
*/
public function isContentAvailable()
{
return $this->contentAvailable;
}
/**
* is mutable content
*
* @return bool
*/
public function isMutableContent()
{
return $this->mutableContent;
}
/**
* is delay white idle.
*
* @return bool
*/
public function isDelayWhileIdle()
{
return $this->delayWhileIdle;
}
/**
* get time to live.
*
* @return null|int
*/
public function getTimeToLive()
{
return $this->timeToLive;
}
/**
* get restricted package name.
*
* @return null|string
*/
public function getRestrictedPackageName()
{
return $this->restrictedPackageName;
}
/**
* is dry run.
*
* @return bool
*/
public function isDryRun()
{
return $this->dryRun;
}
/**
* build an instance of Options.
*
* @return Options
*/
public function build()
{
return new Options($this);
}
}
/**
* Class OptionsPriorities.
*/
final class OptionsPriorities
{
/**
* @const high priority : iOS, these correspond to APNs priorities 10.
*/
const high = 'high';
/**
* @const normal priority : iOS, these correspond to APNs priorities 5
*/
const normal = 'normal';
/**
* @return array priorities available in fcm
*
* @throws \ReflectionException
*/
public static function getPriorities()
{
$class = new ReflectionClass(__CLASS__);
return $class->getConstants();
}
/**
* check if this priority is supported by fcm.
*
* @param $priority
*
* @return bool
*
* @throws \ReflectionException
*/
public static function isValid($priority)
{
return in_array($priority, static::getPriorities());
}
}

View File

@@ -1,38 +0,0 @@
<?php
namespace LaravelFCM\Message;
use Illuminate\Contracts\Support\Arrayable;
/**
* Class PayloadData.
*/
class PayloadData implements Arrayable
{
/**
* @internal
*
* @var array
*/
protected $data;
/**
* PayloadData constructor.
*
* @param PayloadDataBuilder $builder
*/
public function __construct(PayloadDataBuilder $builder)
{
$this->data = $builder->getData();
}
/**
* Transform payloadData to array.
*
* @return array
*/
public function toArray()
{
return $this->data;
}
}

View File

@@ -1,78 +0,0 @@
<?php
namespace LaravelFCM\Message;
/**
* Class PayloadDataBuilder.
*
* Official google documentation :
*
* @link http://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
*/
class PayloadDataBuilder
{
/**
* @internal
*
* @var array
*/
protected $data;
/**
* add data to existing data.
*
* @param array $data
*
* @return PayloadDataBuilder
*/
public function addData(array $data)
{
$this->data = $this->data ?: [];
$this->data = array_merge($data, $this->data);
return $this;
}
/**
* erase data with new data.
*
* @param array $data
*
* @return PayloadDataBuilder
*/
public function setData(array $data)
{
$this->data = $data;
return $this;
}
/**
* Remove all data.
*/
public function removeAllData()
{
$this->data = null;
}
/**
* return data.
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* generate a PayloadData.
*
* @return PayloadData new PayloadData instance
*/
public function build()
{
return new PayloadData($this);
}
}

View File

@@ -1,155 +0,0 @@
<?php
namespace LaravelFCM\Message;
use Illuminate\Contracts\Support\Arrayable;
/**
* Class PayloadNotification.
*/
class PayloadNotification implements Arrayable
{
/**
* @internal
*
* @var null|string
*/
protected $title;
/**
* @internal
*
* @var null|string
*/
protected $body;
/**
* @internal
*
* @var null/string
*/
protected $channelId;
/**
* @internal
*
* @var null|string
*/
protected $icon;
/**
* @internal
*
* @var null|string
*/
protected $sound;
/**
* @internal
*
* @var null|string
*/
protected $badge;
/**
* @internal
*
* @var null|string
*/
protected $tag;
/**
* @internal
*
* @var null|string
*/
protected $color;
/**
* @internal
*
* @var null|string
*/
protected $clickAction;
/**
* @internal
*
* @var null|string
*/
protected $bodyLocationKey;
/**
* @internal
*
* @var null|string
*/
protected $bodyLocationArgs;
/**
* @internal
*
* @var null|string
*/
protected $titleLocationKey;
/**
* @internal
*
* @var null|string
*/
protected $titleLocationArgs;
/**
* PayloadNotification constructor.
*
* @param PayloadNotificationBuilder $builder
*/
public function __construct(PayloadNotificationBuilder $builder)
{
$this->title = $builder->getTitle();
$this->body = $builder->getBody();
$this->channelId = $builder->getChannelId();
$this->icon = $builder->getIcon();
$this->sound = $builder->getSound();
$this->badge = $builder->getBadge();
$this->tag = $builder->getTag();
$this->color = $builder->getColor();
$this->clickAction = $builder->getClickAction();
$this->bodyLocationKey = $builder->getBodyLocationKey();
$this->bodyLocationArgs = $builder->getBodyLocationArgs();
$this->titleLocationKey = $builder->getTitleLocationKey();
$this->titleLocationArgs = $builder->getTitleLocationArgs();
}
/**
* convert PayloadNotification to array.
*
* @return array
*/
public function toArray()
{
$notification = [
'title' => $this->title,
'body' => $this->body,
'android_channel_id' => $this->channelId,
'icon' => $this->icon,
'sound' => $this->sound,
'badge' => $this->badge,
'tag' => $this->tag,
'color' => $this->color,
'click_action' => $this->clickAction,
'body_loc_key' => $this->bodyLocationKey,
'body_loc_args' => $this->bodyLocationArgs,
'title_loc_key' => $this->titleLocationKey,
'title_loc_args' => $this->titleLocationArgs,
];
// remove null values
$notification = array_filter($notification, function($value) {
return $value !== null;
});
return $notification;
}
}

View File

@@ -1,447 +0,0 @@
<?php
namespace LaravelFCM\Message;
/**
* Class PayloadNotificationBuilder.
*
* Official google documentation :
*
* @link http://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
*/
class PayloadNotificationBuilder
{
/**
* @internal
*
* @var null|string
*/
protected $title;
/**
* @internal
*
* @var null|string
*/
protected $body;
/**
* @internal
*
* @var null|string
*/
protected $icon;
/**
* @internal
*
* @var null|string
*/
protected $sound;
/**
* @internal
*
* @var null|string
*/
protected $channelId;
/**
* @internal
*
* @var null|string
*/
protected $badge;
/**
* @internal
*
* @var null|string
*/
protected $tag;
/**
* @internal
*
* @var null|string
*/
protected $color;
/**
* @internal
*
* @var null|string
*/
protected $clickAction;
/**
* @internal
*
* @var null|string
*/
protected $bodyLocationKey;
/**
* @internal
*
* @var null|string
*/
protected $bodyLocationArgs;
/**
* @internal
*
* @var null|string
*/
protected $titleLocationKey;
/**
* @internal
*
* @var null|string
*/
protected $titleLocationArgs;
/**
* Title must be present on android notification and ios (watch) notification.
*
* @param string $title
*/
public function __construct($title = null)
{
$this->title = $title;
}
/**
* Indicates notification title. This field is not visible on iOS phones and tablets.
* but it is required for android.
*
* @param string $title
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Indicates notification body text.
*
* @param string $body
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* Set a channel ID for android API >= 26.
*
* @param string $channelId
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setChannelId($channelId)
{
$this->channelId = $channelId;
return $this;
}
/**
* Supported Android
* Indicates notification icon. example : Sets value to myicon for drawable resource myicon.
*
* @param string $icon
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setIcon($icon)
{
$this->icon = $icon;
return $this;
}
/**
* Indicates a sound to play when the device receives a notification.
* Supports default or the filename of a sound resource bundled in the app.
*
* @param string $sound
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setSound($sound)
{
$this->sound = $sound;
return $this;
}
/**
* Supported Ios.
*
* Indicates the badge on the client app home icon.
*
* @param string $badge
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setBadge($badge)
{
$this->badge = $badge;
return $this;
}
/**
* Supported Android.
*
* Indicates whether each notification results in a new entry in the notification drawer on Android.
* If not set, each request creates a new notification.
* If set, and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.
*
* @param string $tag
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setTag($tag)
{
$this->tag = $tag;
return $this;
}
/**
* Supported Android.
*
* Indicates color of the icon, expressed in #rrggbb format
*
* @param string $color
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setColor($color)
{
$this->color = $color;
return $this;
}
/**
* Indicates the action associated with a user click on the notification.
*
* @param string $action
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setClickAction($action)
{
$this->clickAction = $action;
return $this;
}
/**
* Indicates the key to the title string for localization.
*
* @param string $titleKey
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setTitleLocationKey($titleKey)
{
$this->titleLocationKey = $titleKey;
return $this;
}
/**
* Indicates the string value to replace format specifiers in the title string for localization.
*
* @param mixed $titleArgs
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setTitleLocationArgs($titleArgs)
{
$this->titleLocationArgs = $titleArgs;
return $this;
}
/**
* Indicates the key to the body string for localization.
*
* @param string $bodyKey
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setBodyLocationKey($bodyKey)
{
$this->bodyLocationKey = $bodyKey;
return $this;
}
/**
* Indicates the string value to replace format specifiers in the body string for localization.
*
* @param mixed $bodyArgs
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setBodyLocationArgs($bodyArgs)
{
$this->bodyLocationArgs = $bodyArgs;
return $this;
}
/**
* Get title.
*
* @return null|string
*/
public function getTitle()
{
return $this->title;
}
/**
* Get body.
*
* @return null|string
*/
public function getBody()
{
return $this->body;
}
/**
* Get channel id for android api >= 26
*
* @return null|string
*/
public function getChannelId()
{
return $this->channelId;
}
/**
* Get Icon.
*
* @return null|string
*/
public function getIcon()
{
return $this->icon;
}
/**
* Get Sound.
*
* @return null|string
*/
public function getSound()
{
return $this->sound;
}
/**
* Get Badge.
*
* @return null|string
*/
public function getBadge()
{
return $this->badge;
}
/**
* Get Tag.
*
* @return null|string
*/
public function getTag()
{
return $this->tag;
}
/**
* Get Color.
*
* @return null|string
*/
public function getColor()
{
return $this->color;
}
/**
* Get ClickAction.
*
* @return null|string
*/
public function getClickAction()
{
return $this->clickAction;
}
/**
* Get BodyLocationKey.
*
* @return null|string
*/
public function getBodyLocationKey()
{
return $this->bodyLocationKey;
}
/**
* Get BodyLocationArgs.
*
* @return null|string|array
*/
public function getBodyLocationArgs()
{
return $this->bodyLocationArgs;
}
/**
* Get TitleLocationKey.
*
* @return string
*/
public function getTitleLocationKey()
{
return $this->titleLocationKey;
}
/**
* GetTitleLocationArgs.
*
* @return null|string|array
*/
public function getTitleLocationArgs()
{
return $this->titleLocationArgs;
}
/**
* Build an PayloadNotification.
*
* @return PayloadNotification
*/
public function build()
{
return new PayloadNotification($this);
}
}

View File

@@ -1,226 +0,0 @@
<?php
namespace LaravelFCM\Message;
use Closure;
use LaravelFCM\Message\Exceptions\NoTopicProvidedException;
/**
* Class Topics.
*
* Create topic or a topic condition
*/
class Topics
{
/**
* @internal
*
* @var array of element in the condition
*/
public $conditions = [];
/**
* Add a topic, this method should be called before any conditional topic.
*
* @param string $first topicName
*
* @return $this
*/
public function topic($first)
{
$this->conditions[] = compact('first');
return $this;
}
/**
* Add a or condition to the precedent topic set.
*
* Parenthesis is a closure
*
* Equivalent of this: **'TopicA' in topic' || 'TopicB' in topics**
*
* ```
* $topic = new Topics();
* $topic->topic('TopicA')
* ->orTopic('TopicB');
* ```
*
* Equivalent of this: **'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)**
*
* ```
* $topic = new Topics();
* $topic->topic('TopicA')
* ->andTopic(function($condition) {
* $condition->topic('TopicB')->orTopic('TopicC');
* });
* ```
*
* > Note: Only two operators per expression are supported by fcm
*
* @param string|Closure $first topicName or closure
*
* @return Topics
*/
public function orTopic($first)
{
return $this->on($first, ' || ');
}
/**
* Add a and condition to the precedent topic set.
*
* Parenthesis is a closure
*
* Equivalent of this: **'TopicA' in topic' && 'TopicB' in topics**
*
* ```
* $topic = new Topics();
* $topic->topic('TopicA')
* ->anTopic('TopicB');
* ```
*
* Equivalent of this: **'TopicA' in topics || ('TopicB' in topics && 'TopicC' in topics)**
*
* ```
* $topic = new Topics();
* $topic->topic('TopicA')
* ->orTopic(function($condition) {
* $condition->topic('TopicB')->AndTopic('TopicC');
* });
* ```
*
* > Note: Only two operators per expression are supported by fcm
*
* @param string|Closure $first topicName or closure
*
* @return Topics
*/
public function andTopic($first)
{
return $this->on($first, ' && ');
}
/**
* @internal
*
* @param $first
* @param $condition
*
* @return $this|Topics
*/
private function on($first, $condition)
{
if ($first instanceof Closure) {
return $this->nest($first, $condition);
}
$this->conditions[] = compact('condition', 'first');
return $this;
}
/**
* @internal
*
* @param Closure $callback
* @param $condition
*
* @return $this
*/
public function nest(Closure $callback, $condition)
{
$topic = new static();
$callback($topic);
if (count($topic->conditions)) {
$open_parenthesis = '(';
$topic = $topic->conditions;
$close_parenthesis = ')';
$this->conditions[] = compact('condition', 'open_parenthesis', 'topic', 'close_parenthesis');
}
return $this;
}
/**
* Transform to array.
*
* @return array|string
*
* @throws NoTopicProvided
*/
public function build()
{
$this->checkIfOneTopicExist();
if ($this->hasOnlyOneTopic()) {
foreach ($this->conditions[0] as $topic) {
return '/topics/'.$topic;
}
}
return [
'condition' => $this->topicsForFcm($this->conditions),
];
}
/**
* @internal
*
* @param $conditions
*
* @return string
*/
private function topicsForFcm($conditions)
{
$condition = '';
foreach ($conditions as $partial) {
if (array_key_exists('condition', $partial)) {
$condition .= $partial['condition'];
}
if (array_key_exists('first', $partial)) {
$topic = $partial['first'];
$condition .= "'$topic' in topics";
}
if (array_key_exists('open_parenthesis', $partial)) {
$condition .= $partial['open_parenthesis'];
}
if (array_key_exists('topic', $partial)) {
$condition .= $this->topicsForFcm($partial['topic']);
}
if (array_key_exists('close_parenthesis', $partial)) {
$condition .= $partial['close_parenthesis'];
}
}
return $condition;
}
/**
* Check if only one topic was set.
*
* @return bool
*/
public function hasOnlyOneTopic()
{
return count($this->conditions) == 1;
}
/**
* @internal
*
* @throws NoTopicProvidedException
*/
private function checkIfOneTopicExist()
{
if (!count($this->conditions)) {
throw new NoTopicProvidedException('At least one topic must be provided');
}
}
}