update v1.0.7.9 R.C.
This is a Release Candidate. We are still testing.
This commit is contained in:
13
vendor/brozot/laravel-fcm/src/Message/Exceptions/InvalidOptionsException.php
vendored
Normal file
13
vendor/brozot/laravel-fcm/src/Message/Exceptions/InvalidOptionsException.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php namespace LaravelFCM\Message\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
||||
|
||||
/**
|
||||
* Class InvalidOptionsException
|
||||
*
|
||||
* @package LaravelFCM\Response\Exceptions
|
||||
*/
|
||||
class InvalidOptionsException extends Exception {
|
||||
|
||||
}
|
||||
13
vendor/brozot/laravel-fcm/src/Message/Exceptions/NoTopicProvidedException.php
vendored
Normal file
13
vendor/brozot/laravel-fcm/src/Message/Exceptions/NoTopicProvidedException.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php namespace LaravelFCM\Message\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
||||
|
||||
/**
|
||||
* Class NoTopicProvidedException
|
||||
*
|
||||
* @package LaravelFCM\Response\Exceptions
|
||||
*/
|
||||
class NoTopicProvidedException extends Exception {
|
||||
|
||||
}
|
||||
93
vendor/brozot/laravel-fcm/src/Message/Options.php
vendored
Normal file
93
vendor/brozot/laravel-fcm/src/Message/Options.php
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php namespace LaravelFCM\Message;
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
/**
|
||||
* Class Options
|
||||
*
|
||||
* @package LaravelFCM\Message
|
||||
*/
|
||||
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 $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->delayWhileIdle = $builder->isDelayWhileIdle();
|
||||
$this->timeToLive = $builder->getTimeToLive();
|
||||
$this->restrictedPackageName = $builder->getRestrictedPackageName();
|
||||
$this->isDryRun = $builder->isDryRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform Option to array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function toArray()
|
||||
{
|
||||
$contentAvailable = $this->contentAvailable ? true : null;
|
||||
$delayWhileIdle = $this->delayWhileIdle ? true : null;
|
||||
$dryRun = $this->isDryRun ? true : null;
|
||||
|
||||
$options = [
|
||||
'collapse_key' => $this->collapseKey,
|
||||
'priority' => $this->priority,
|
||||
'content_available' => $contentAvailable,
|
||||
'delay_while_idle' => $delayWhileIdle,
|
||||
'time_to_live' => $this->timeToLive,
|
||||
'restricted_package_name' => $this->restrictedPackageName,
|
||||
'dry_run' => $dryRun
|
||||
];
|
||||
|
||||
return array_filter($options);
|
||||
}
|
||||
}
|
||||
298
vendor/brozot/laravel-fcm/src/Message/OptionsBuilder.php
vendored
Normal file
298
vendor/brozot/laravel-fcm/src/Message/OptionsBuilder.php
vendored
Normal file
@@ -0,0 +1,298 @@
|
||||
<?php namespace LaravelFCM\Message;
|
||||
|
||||
use Exception;
|
||||
use LaravelFCM\Message\Exceptions\InvalidOptionsException;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Builder for creation of options used by FCM
|
||||
*
|
||||
* Class OptionsBuilder
|
||||
*
|
||||
* @package LaravelFCM\Message\OptionsBuilder
|
||||
*
|
||||
* Form more information about options, please refer to google official documentation :
|
||||
* @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 boolean
|
||||
*/
|
||||
protected $contentAvailable = false;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var boolean
|
||||
*/
|
||||
protected $delayWhileIdle = false;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var string
|
||||
*/
|
||||
protected $timeToLive;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var string
|
||||
*/
|
||||
protected $restrictedPackageName;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var boolean
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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 boolean $contentAvailable
|
||||
*
|
||||
* @return \LaravelFCM\Message\OptionsBuilder
|
||||
*/
|
||||
public function setContentAvailable($contentAvailable)
|
||||
{
|
||||
$this->contentAvailable = $contentAvailable;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* When this parameter is set to true, it indicates that the message should not be sent until the device becomes active.
|
||||
*
|
||||
* @param boolean $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 InvalidOptionException
|
||||
*/
|
||||
public function setTimeToLive($timeToLive)
|
||||
{
|
||||
if ($timeToLive < 0 || $timeToLive > 2419200) {
|
||||
throw new InvalidOptionException("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 boolean $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 boolean
|
||||
*/
|
||||
public function isContentAvailable()
|
||||
{
|
||||
return $this->contentAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
* is delay white idle
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
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 boolean
|
||||
*/
|
||||
public function isDryRun()
|
||||
{
|
||||
return $this->dryRun;
|
||||
}
|
||||
|
||||
/**
|
||||
* build an instance of Options
|
||||
*
|
||||
* @return Options
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return new Options($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class OptionsPriorities
|
||||
*
|
||||
* @package LaravelFCM\Message\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
|
||||
*/
|
||||
static function getPriorities()
|
||||
{
|
||||
$class = new ReflectionClass(__CLASS__);
|
||||
return $class->getConstants();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if this priority is supported by fcm
|
||||
*
|
||||
* @param $priority
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
static function isValid($priority)
|
||||
{
|
||||
return in_array($priority, static::getPriorities());
|
||||
}
|
||||
}
|
||||
38
vendor/brozot/laravel-fcm/src/Message/PayloadData.php
vendored
Normal file
38
vendor/brozot/laravel-fcm/src/Message/PayloadData.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php namespace LaravelFCM\Message;
|
||||
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
/**
|
||||
* Class PayloadData
|
||||
*
|
||||
* @package LaravelFCM\Message
|
||||
*/
|
||||
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
|
||||
*/
|
||||
function toArray()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
77
vendor/brozot/laravel-fcm/src/Message/PayloadDataBuilder.php
vendored
Normal file
77
vendor/brozot/laravel-fcm/src/Message/PayloadDataBuilder.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php namespace LaravelFCM\Message;
|
||||
|
||||
/**
|
||||
* Class PayloadDataBuilder
|
||||
*
|
||||
* Official google documentation :
|
||||
* @link http://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
|
||||
*
|
||||
* @package LaravelFCM\Message
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
134
vendor/brozot/laravel-fcm/src/Message/PayloadNotification.php
vendored
Normal file
134
vendor/brozot/laravel-fcm/src/Message/PayloadNotification.php
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php namespace LaravelFCM\Message;
|
||||
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
/**
|
||||
* Class PayloadNotification
|
||||
*
|
||||
* @package LaravelFCM\Message
|
||||
*/
|
||||
class PayloadNotification implements Arrayable {
|
||||
|
||||
/**
|
||||
* @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 $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->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
|
||||
*/
|
||||
function toArray()
|
||||
{
|
||||
$notification = [
|
||||
'title' => $this->title,
|
||||
'body' => $this->body,
|
||||
'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);
|
||||
|
||||
return $notification;
|
||||
}
|
||||
}
|
||||
401
vendor/brozot/laravel-fcm/src/Message/PayloadNotificationBuilder.php
vendored
Normal file
401
vendor/brozot/laravel-fcm/src/Message/PayloadNotificationBuilder.php
vendored
Normal file
@@ -0,0 +1,401 @@
|
||||
<?php namespace LaravelFCM\Message;
|
||||
|
||||
/**
|
||||
* Class PayloadNotificationBuilder
|
||||
*
|
||||
* Official google documentation :
|
||||
* @link http://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
|
||||
*
|
||||
* @package LaravelFCM\Message
|
||||
*/
|
||||
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 $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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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);
|
||||
}
|
||||
}
|
||||
227
vendor/brozot/laravel-fcm/src/Message/Topics.php
vendored
Normal file
227
vendor/brozot/laravel-fcm/src/Message/Topics.php
vendored
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php namespace LaravelFCM\Message;
|
||||
|
||||
|
||||
use Closure;
|
||||
use LaravelFCM\Message\Exceptions\NoTopicProvidedException;
|
||||
|
||||
/**
|
||||
* Class Topics
|
||||
*
|
||||
* Create topic or a topic condition
|
||||
*
|
||||
* @package LaravelFCM\Message
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user