laravel-6 support

This commit is contained in:
RafficMohammed
2023-01-08 01:17:22 +05:30
parent 1a5c16ae4b
commit 774eed8b0e
4962 changed files with 279380 additions and 297961 deletions

View File

@@ -1,9 +0,0 @@
<?php
namespace Sly\NotificationPusher\Model;
class ApnsMessage extends Message
{
}

View File

@@ -1,77 +0,0 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* @author Cédric Dugat <cedric@dugat.me>
*/
abstract class BaseOptionedModel
{
/**
* @var array
*/
protected $options = [];
/**
* @return array
*/
public function getOptions()
{
return $this->options;
}
/**
* @param string $key Key
*
* @return boolean
*/
public function hasOption($key)
{
return array_key_exists($key, $this->options);
}
/**
* @param string $key Key
* @param mixed $default Default
*
* @return mixed
*/
public function getOption($key, $default = null)
{
return $this->hasOption($key) ? $this->options[$key] : $default;
}
/**
* @param array $options Options
*
* @return BaseOptionedModel
*/
public function setOptions($options)
{
$this->options = $options;
return $this;
}
/**
* @param string $key Key
* @param mixed $value Value
*
* @return mixed
*/
public function setOption($key, $value)
{
$this->options[$key] = $value;
return $value;
}
}

View File

@@ -1,77 +0,0 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* @author Cédric Dugat <cedric@dugat.me>
*/
abstract class BaseParameteredModel
{
/**
* @var array
*/
protected $parameters = [];
/**
* @return array
*/
public function getParameters()
{
return $this->parameters;
}
/**
* @param string $key Key
*
* @return boolean
*/
public function hasParameter($key)
{
return array_key_exists($key, $this->parameters);
}
/**
* @param string $key Key
* @param mixed $default Default
*
* @return mixed
*/
public function getParameter($key, $default = null)
{
return $this->hasParameter($key) ? $this->parameters[$key] : $default;
}
/**
* @param array $parameters Parameters
*
* @return BaseParameteredModel
*/
public function setParameters($parameters)
{
$this->parameters = $parameters;
return $this;
}
/**
* @param string $key Key
* @param mixed $value Value
*
* @return mixed
*/
public function setParameter($key, $value)
{
$this->parameters[$key] = $value;
return $value;
}
}

View File

@@ -1,53 +0,0 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* @author Cédric Dugat <cedric@dugat.me>
*/
class Device extends BaseParameteredModel implements DeviceInterface
{
/**
* @var string
*/
private $token;
/**
* @param string $token Token
* @param array $parameters Parameters
*/
public function __construct($token, array $parameters = [])
{
$this->token = $token;
$this->parameters = $parameters;
}
/**
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* @param string $token Token
*
* @return DeviceInterface
*/
public function setToken($token)
{
$this->token = $token;
return $this;
}
}

View File

@@ -1,30 +0,0 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* @author Cédric Dugat <cedric@dugat.me>
*/
interface DeviceInterface
{
/**
* @return string
*/
public function getToken();
/**
* @param string $token Token
*
* @return DeviceInterface
*/
public function setToken($token);
}

View File

@@ -1,28 +0,0 @@
<?php
namespace Sly\NotificationPusher\Model;
class GcmMessage extends Message
{
/**
* @var array
*/
private $notificationData = [];
/**
* @return array
*/
public function getNotificationData()
{
return $this->notificationData;
}
/**
* @param array $notificationData
*/
public function setNotificationData($notificationData)
{
$this->notificationData = $notificationData;
}
}

View File

@@ -1,53 +0,0 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* @author Cédric Dugat <cedric@dugat.me>
*/
class Message extends BaseOptionedModel implements MessageInterface
{
/**
* @var string
*/
protected $text;
/**
* @param string $text Text
* @param array $options Options
*/
public function __construct($text, array $options = [])
{
$this->text = $text;
$this->options = $options;
}
/**
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* @param string $text Text
*
* @return MessageInterface
*/
public function setText($text)
{
$this->text = $text;
return $this;
}
}

View File

@@ -1,30 +0,0 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* @author Cédric Dugat <cedric@dugat.me>
*/
interface MessageInterface
{
/**
* @return string
*/
public function getText();
/**
* @param string $text Text
*
* @return MessageInterface
*/
public function setText($text);
}

View File

@@ -1,242 +0,0 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
use Sly\NotificationPusher\Adapter\AdapterInterface;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Collection\ResponseCollection;
use Sly\NotificationPusher\Exception\AdapterException;
/**
* @author Cédric Dugat <cedric@dugat.me>
*/
class Push extends BaseOptionedModel implements PushInterface
{
/**
* @var string
*/
private $status;
/**
* @var AdapterInterface
*/
private $adapter;
/**
* @var MessageInterface
*/
private $message;
/**
* @var DeviceCollection
*/
private $devices;
/**
* @var \DateTime
*/
private $pushedAt;
/**
* @var ResponseCollection
*/
private $responses;
/**
* @param AdapterInterface $adapter Adapter
* @param DeviceInterface|DeviceCollection $devices Device(s)
* @param MessageInterface $message Message
* @param array $options Options
*
* Options are adapters specific ones, like Apns "badge" or "sound" option for example.
* Of course, they can be more general.
*
* @throws AdapterException
*/
public function __construct(AdapterInterface $adapter, $devices, MessageInterface $message, array $options = [])
{
if ($devices instanceof DeviceInterface) {
$devices = new DeviceCollection([$devices]);
}
$this->adapter = $adapter;
$this->devices = $devices;
$this->message = $message;
$this->options = $options;
$this->status = self::STATUS_PENDING;
$this->checkDevicesTokens();
}
/**
* @throws AdapterException
*/
private function checkDevicesTokens()
{
$devices = $this->getDevices();
$adapter = $this->getAdapter();
foreach ($devices as $device) {
if (false === $adapter->supports($device->getToken())) {
throw new AdapterException(
sprintf(
'Adapter %s does not support %s token\'s device',
(string) $adapter,
$device->getToken()
)
);
}
}
}
/**
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
* @param string $status Status
*
* @return PushInterface
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* @return boolean
*/
public function isPushed()
{
return (bool) (self::STATUS_PUSHED === $this->status);
}
/**
* @return PushInterface
*/
public function pushed()
{
$this->status = self::STATUS_PUSHED;
$this->pushedAt = new \DateTime();
return $this;
}
/**
* @return AdapterInterface
*/
public function getAdapter()
{
return $this->adapter;
}
/**
* @param AdapterInterface $adapter Adapter
*
* @return PushInterface
*/
public function setAdapter(AdapterInterface $adapter)
{
$this->adapter = $adapter;
return $this;
}
/**
* @return MessageInterface
*/
public function getMessage()
{
return $this->message;
}
/**
* @param MessageInterface $message Message
*
* @return PushInterface
*/
public function setMessage(MessageInterface $message)
{
$this->message = $message;
return $this;
}
/**
* @return DeviceCollection
*/
public function getDevices()
{
return $this->devices;
}
/**
* @param DeviceCollection $devices Devices
*
* @return PushInterface
*/
public function setDevices(DeviceCollection $devices)
{
$this->devices = $devices;
$this->checkDevicesTokens();
return $this;
}
/**
* @return ResponseCollection
*/
public function getResponses()
{
if (!$this->responses)
$this->responses = new ResponseCollection();
return $this->responses;
}
/**
* @param DeviceInterface $device
* @param mixed $response
*/
public function addResponse(DeviceInterface $device, $response)
{
$this->getResponses()->add($device->getToken(), $response);
}
/**
* @return \DateTime
*/
public function getPushedAt()
{
return $this->pushedAt;
}
/**
* @param \DateTime $pushedAt PushedAt
*
* @return PushInterface
*/
public function setPushedAt(\DateTime $pushedAt)
{
$this->pushedAt = $pushedAt;
return $this;
}
}

View File

@@ -1,107 +0,0 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
use DateTime;
use Sly\NotificationPusher\Adapter\AdapterInterface;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Collection\ResponseCollection;
interface PushInterface
{
/**
* Constants define available statuses
*/
const STATUS_PENDING = 'pending';
const STATUS_PUSHED = 'sent';
/**
* @return string
*/
public function getStatus();
/**
* @param string $status Status
*
* @return PushInterface
*/
public function setStatus($status);
/**
* @return boolean
*/
public function isPushed();
/**
* @return PushInterface
*/
public function pushed();
/**
* @return AdapterInterface
*/
public function getAdapter();
/**
* @param AdapterInterface $adapter Adapter
*
* @return PushInterface
*/
public function setAdapter(AdapterInterface $adapter);
/**
* @return MessageInterface
*/
public function getMessage();
/**
* @param MessageInterface $message Message
*
* @return PushInterface
*/
public function setMessage(MessageInterface $message);
/**
* @return DeviceCollection
*/
public function getDevices();
/**
* @param DeviceCollection $devices Devices
*
* @return PushInterface
*/
public function setDevices(DeviceCollection $devices);
/**
* @return ResponseCollection
*/
public function getResponses();
/**
* @param DeviceInterface $device
* @param mixed $response
*/
public function addResponse(DeviceInterface $device, $response);
/**
* @return DateTime
*/
public function getPushedAt();
/**
* @param DateTime $pushedAt PushedAt
*
* @return PushInterface
*/
public function setPushedAt(DateTime $pushedAt);
}

View File

@@ -1,92 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: seyfer
* Date: 09.08.17
* Time: 17:57
*/
namespace Sly\NotificationPusher\Model;
use Sly\NotificationPusher\Collection\PushCollection;
/**
* @author Oleg Abrazhaev <seyferseed@gmail.com>
*/
class Response implements ResponseInterface
{
/**
* @var array
*/
private $parsedResponses = [];
/**
* @var array
*/
private $originalResponses = [];
/**
* @var PushCollection
*/
private $pushCollection;
public function __construct()
{
$this->pushCollection = new PushCollection();
}
/**
* @param DeviceInterface $device
* @param array $response
*/
public function addParsedResponse(DeviceInterface $device, $response)
{
if (!is_array($response)) {
throw new \InvalidArgumentException('Response must be array type');
}
$this->parsedResponses[$device->getToken()] = $response;
}
/**
* @param DeviceInterface $device
* @param mixed $originalResponse
*/
public function addOriginalResponse(DeviceInterface $device, $originalResponse)
{
$this->originalResponses[$device->getToken()] = $originalResponse;
}
/**
* @param PushInterface $push Push
*/
public function addPush(PushInterface $push)
{
$this->pushCollection->add($push);
}
/**
* @return array
*/
public function getParsedResponses()
{
return $this->parsedResponses;
}
/**
* @return mixed
*/
public function getOriginalResponses()
{
return $this->originalResponses;
}
/**
* @return PushCollection
*/
public function getPushCollection()
{
return $this->pushCollection;
}
}

View File

@@ -1,49 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: seyfer
* Date: 10.08.17
* Time: 10:30
*/
namespace Sly\NotificationPusher\Model;
use Sly\NotificationPusher\Collection\PushCollection;
/**
* @author Oleg Abrazhaev <seyferseed@gmail.com>
*/
interface ResponseInterface
{
/**
* @param DeviceInterface $device
* @param array $response
*/
public function addParsedResponse(DeviceInterface $device, $response);
/**
* @param DeviceInterface $device
* @param mixed $originalResponse
*/
public function addOriginalResponse(DeviceInterface $device, $originalResponse);
/**
* @param PushInterface $push Push
*/
public function addPush(PushInterface $push);
/**
* @return array
*/
public function getParsedResponses();
/**
* @return mixed
*/
public function getOriginalResponses();
/**
* @return PushCollection
*/
public function getPushCollection();
}