updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -11,29 +11,23 @@
namespace Sly\NotificationPusher\Adapter;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Model\PushInterface;
use Sly\NotificationPusher\Model\Response;
use Sly\NotificationPusher\Model\ResponseInterface;
/**
* AdapterInterface.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
interface AdapterInterface
{
/**
* Push.
* @param PushInterface $push Push
*
* @param \Sly\NotificationPusher\Model\PushInterface $push Push
*
* @return \Sly\NotificationPusher\Collection\DeviceCollection
* @return DeviceCollection
*/
public function push(PushInterface $push);
/**
* Supports.
*
* @param string $token Token
*
* @return boolean
@@ -51,39 +45,29 @@ interface AdapterInterface
public function setResponse(ResponseInterface $response);
/**
* Get defined parameters.
*
* @return array
*/
public function getDefinedParameters();
/**
* Get default parameters.
*
* @return array
*/
public function getDefaultParameters();
/**
* Get required parameters.
*
* @return array
*/
public function getRequiredParameters();
/**
* Get Environment.
*
* @return string
*/
public function getEnvironment();
/**
* Set Environment.
*
* @param string $environment Environment value to set
*
* @return \Sly\NotificationPusher\Adapter\AdapterInterface
* @return AdapterInterface
*/
public function setEnvironment($environment);
}

View File

@@ -16,17 +16,17 @@ use Sly\NotificationPusher\Exception\AdapterException;
use Sly\NotificationPusher\Exception\PushException;
use Sly\NotificationPusher\Model\BaseOptionedModel;
use Sly\NotificationPusher\Model\DeviceInterface;
use Sly\NotificationPusher\Model\MessageInterface;
use Sly\NotificationPusher\Model\PushInterface;
use ZendService\Apple\Apns\Client\AbstractClient as ServiceAbstractClient;
use ZendService\Apple\Apns\Client\Feedback as ServiceFeedbackClient;
use ZendService\Apple\Apns\Client\Message as ServiceClient;
use ZendService\Apple\Apns\Message as ServiceMessage;
use ZendService\Apple\Apns\Message\Alert as ServiceAlert;
use ZendService\Apple\Apns\Response\Feedback;
use ZendService\Apple\Apns\Response\Message as ServiceResponse;
/**
* APNS adapter.
*
* @uses \Sly\NotificationPusher\Adapter\BaseAdapter
*
* @author Cédric Dugat <cedric@dugat.me>
@@ -47,7 +47,7 @@ class Apns extends BaseAdapter implements FeedbackAdapterInterface
/**
* {@inheritdoc}
*
* @throws \Sly\NotificationPusher\Exception\AdapterException
* @throws AdapterException
*/
public function __construct(array $parameters = [])
{
@@ -63,7 +63,7 @@ class Apns extends BaseAdapter implements FeedbackAdapterInterface
/**
* {@inheritdoc}
*
* @throws \Sly\NotificationPusher\Exception\PushException
* @throws PushException
*/
public function push(PushInterface $push)
{
@@ -72,15 +72,14 @@ class Apns extends BaseAdapter implements FeedbackAdapterInterface
$pushedDevices = new DeviceCollection();
foreach ($push->getDevices() as $device) {
/** @var \ZendService\Apple\Apns\Message $message */
$message = $this->getServiceMessageFromOrigin($device, $push->getMessage());
try {
/** @var \ZendService\Apple\Apns\Response\Message $response */
/** @var ServiceResponse $response */
$response = $client->send($message);
$responseArr = [
'id' => $response->getId(),
'id' => $response->getId(),
'token' => $response->getCode(),
];
$push->addResponse($device, $responseArr);
@@ -105,17 +104,15 @@ class Apns extends BaseAdapter implements FeedbackAdapterInterface
}
/**
* Feedback.
*
* @return array
*/
public function getFeedback()
{
$client = $this->getOpenedFeedbackClient();
$responses = [];
$client = $this->getOpenedFeedbackClient();
$responses = [];
$serviceResponses = $client->feedback();
/** @var \ZendService\Apple\Apns\Response\Feedback $response */
/** @var Feedback $response */
foreach ($serviceResponses as $response) {
$responses[$response->getToken()] = new \DateTime(date('c', $response->getTime()));
}
@@ -124,11 +121,9 @@ class Apns extends BaseAdapter implements FeedbackAdapterInterface
}
/**
* Get opened client.
* @param ServiceAbstractClient|null $client Client
*
* @param \ZendService\Apple\Apns\Client\AbstractClient|null $client Client
*
* @return \ZendService\Apple\Apns\Client\AbstractClient
* @return ServiceAbstractClient
*/
public function getOpenedClient(ServiceAbstractClient $client = null)
{
@@ -146,8 +141,6 @@ class Apns extends BaseAdapter implements FeedbackAdapterInterface
}
/**
* Get opened ServiceClient
*
* @return ServiceClient
*/
protected function getOpenedServiceClient()
@@ -160,8 +153,6 @@ class Apns extends BaseAdapter implements FeedbackAdapterInterface
}
/**
* Get opened ServiceFeedbackClient
*
* @return ServiceFeedbackClient
*/
private function getOpenedFeedbackClient()
@@ -174,25 +165,23 @@ class Apns extends BaseAdapter implements FeedbackAdapterInterface
}
/**
* Get service message from origin.
* @param DeviceInterface $device Device
* @param BaseOptionedModel|MessageInterface $message Message
*
* @param \Sly\NotificationPusher\Model\DeviceInterface $device Device
* @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
*
* @return \ZendService\Apple\Apns\Message
* @return ServiceMessage
*/
public function getServiceMessageFromOrigin(DeviceInterface $device, BaseOptionedModel $message)
{
$badge = ($message->hasOption('badge'))
? (int)($message->getOption('badge') + $device->getParameter('badge', 0))
? (int) ($message->getOption('badge') + $device->getParameter('badge', 0))
: false;
$sound = $message->getOption('sound');
$sound = $message->getOption('sound');
$contentAvailable = $message->getOption('content-available');
$mutableContent = $message->getOption('mutable-content');
$category = $message->getOption('category');
$urlArgs = $message->getOption('urlArgs');
$expire = $message->getOption('expire');
$mutableContent = $message->getOption('mutable-content');
$category = $message->getOption('category');
$urlArgs = $message->getOption('urlArgs');
$expire = $message->getOption('expire');
$alert = new ServiceAlert(
$message->getText(),
@@ -267,7 +256,7 @@ class Apns extends BaseAdapter implements FeedbackAdapterInterface
*/
public function supports($token)
{
return (ctype_xdigit($token) && 64 == strlen($token));
return ctype_xdigit($token);
}
/**

View File

@@ -6,27 +6,24 @@
* Time: 17:03
*/
namespace Sly\Sly\NotificationPusher\Adapter;
namespace Sly\NotificationPusher\Adapter;
use Sly\NotificationPusher\Adapter\BaseAdapter;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Model\PushInterface;
/**
* Class ApnsAPI
* @package Sly\Sly\NotificationPusher\Adapter
*
* @author Oleg Abrazhaev <seyferseed@gmail.com>
* todo: implement with edamov/pushok
*/
class ApnsAPI extends BaseAdapter
{
/**
* Push.
* @param PushInterface $push Push
*
* @param \Sly\NotificationPusher\Model\PushInterface $push Push
*
* @return \Sly\NotificationPusher\Collection\DeviceCollection
* @return DeviceCollection
*/
public function push(PushInterface $push)
{
@@ -34,8 +31,6 @@ class ApnsAPI extends BaseAdapter
}
/**
* Supports.
*
* @param string $token Token
*
* @return boolean
@@ -46,8 +41,6 @@ class ApnsAPI extends BaseAdapter
}
/**
* Get defined parameters.
*
* @return array
*/
public function getDefinedParameters()
@@ -56,8 +49,6 @@ class ApnsAPI extends BaseAdapter
}
/**
* Get default parameters.
*
* @return array
*/
public function getDefaultParameters()
@@ -66,12 +57,10 @@ class ApnsAPI extends BaseAdapter
}
/**
* Get required parameters.
*
* @return array
*/
public function getRequiredParameters()
{
// TODO: Implement getRequiredParameters() method.
}
}
}

View File

@@ -18,8 +18,6 @@ use Sly\NotificationPusher\PushManager;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* BaseAdapter.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterface
@@ -40,8 +38,6 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
protected $response;
/**
* Constructor.
*
* @param array $parameters Adapter specific parameters
*/
public function __construct(array $parameters = [])
@@ -51,10 +47,10 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
$resolver->setDefaults($this->getDefaultParameters());
$resolver->setRequired($this->getRequiredParameters());
$reflectedClass = new \ReflectionClass($this);
$reflectedClass = new \ReflectionClass($this);
$this->adapterKey = lcfirst($reflectedClass->getShortName());
$this->parameters = $resolver->resolve($parameters);
$this->response = new Response();
$this->response = new Response();
}
/**
@@ -74,8 +70,6 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
}
/**
* __toString.
*
* @return string
*/
public function __toString()
@@ -84,8 +78,6 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
}
/**
* Get AdapterKey.
*
* @return string
*/
public function getAdapterKey()
@@ -94,8 +86,6 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
}
/**
* Get Environment.
*
* @return string
*/
public function getEnvironment()
@@ -104,11 +94,9 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
}
/**
* Set Environment.
*
* @param string $environment Environment value to set
*
* @return \Sly\NotificationPusher\Adapter\AdapterInterface
* @return AdapterInterface
*/
public function setEnvironment($environment)
{
@@ -118,8 +106,6 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
}
/**
* isDevelopmentEnvironment.
*
* @return boolean
*/
public function isDevelopmentEnvironment()
@@ -128,8 +114,6 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
}
/**
* isProductionEnvironment.
*
* @return boolean
*/
public function isProductionEnvironment()

View File

@@ -8,8 +8,10 @@
namespace Sly\NotificationPusher\Adapter;
/**
* @author Oleg Abrazhaev <seyferseed@gmail.com>
*/
interface FeedbackAdapterInterface
{
public function getFeedback();
}
}

View File

@@ -17,16 +17,17 @@ use Sly\NotificationPusher\Exception\PushException;
use Sly\NotificationPusher\Model\BaseOptionedModel;
use Sly\NotificationPusher\Model\DeviceInterface;
use Sly\NotificationPusher\Model\GcmMessage;
use Sly\NotificationPusher\Model\MessageInterface;
use Sly\NotificationPusher\Model\PushInterface;
use Zend\Http\Client as HttpClient;
use Zend\Http\Client\Adapter\Socket as HttpSocketAdapter;
use ZendService\Google\Exception\InvalidArgumentException as ZendInvalidArgumentException;
use ZendService\Google\Exception\RuntimeException as ServiceRuntimeException;
use ZendService\Google\Gcm\Client as ServiceClient;
use ZendService\Google\Gcm\Message as ServiceMessage;
use ZendService\Google\Gcm\Response;
/**
* GCM adapter.
*
* @uses \Sly\NotificationPusher\Adapter\BaseAdapter
*
* @author Cédric Dugat <cedric@dugat.me>
@@ -34,7 +35,7 @@ use ZendService\Google\Gcm\Message as ServiceMessage;
class Gcm extends BaseAdapter
{
/**
* @var \Zend\Http\Client
* @var HttpClient
*/
private $httpClient;
@@ -54,21 +55,21 @@ class Gcm extends BaseAdapter
/**
* {@inheritdoc}
*
* @throws \Sly\NotificationPusher\Exception\PushException
* @throws PushException
*/
public function push(PushInterface $push)
{
$client = $this->getOpenedClient();
$client = $this->getOpenedClient();
$pushedDevices = new DeviceCollection();
$tokens = array_chunk($push->getDevices()->getTokens(), 100);
$tokens = array_chunk($push->getDevices()->getTokens(), 100);
foreach ($tokens as $tokensRange) {
$message = $this->getServiceMessageFromOrigin($tokensRange, $push->getMessage());
try {
/** @var \ZendService\Google\Gcm\Response $response */
$response = $client->send($message);
/** @var Response $response */
$response = $client->send($message);
$responseResults = $response->getResults();
foreach ($tokensRange as $token) {
@@ -108,7 +109,7 @@ class Gcm extends BaseAdapter
/**
* Get opened client.
*
* @return \ZendService\Google\Gcm\Client
* @return ServiceClient
*/
public function getOpenedClient()
{
@@ -116,10 +117,10 @@ class Gcm extends BaseAdapter
$this->openedClient = new ServiceClient();
$this->openedClient->setApiKey($this->getParameter('apiKey'));
$newClient = new \Zend\Http\Client(
$newClient = new HttpClient(
null,
[
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'sslverifypeer' => false,
]
);
@@ -134,14 +135,14 @@ class Gcm extends BaseAdapter
* Get service message from origin.
*
* @param array $tokens Tokens
* @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
* @param BaseOptionedModel|MessageInterface $message Message
*
* @return \ZendService\Google\Gcm\Message
* @throws \ZendService\Google\Exception\InvalidArgumentException
* @return ServiceMessage
* @throws ZendInvalidArgumentException
*/
public function getServiceMessageFromOrigin(array $tokens, BaseOptionedModel $message)
{
$data = $message->getOptions();
$data = $message->getOptions();
$data['message'] = $message->getText();
$serviceMessage = new ServiceMessage();
@@ -159,6 +160,7 @@ class Gcm extends BaseAdapter
$serviceMessage->setData($data);
$serviceMessage->setCollapseKey($this->getParameter('collapseKey'));
$serviceMessage->setPriority($this->getParameter('priority', 'normal'));
$serviceMessage->setRestrictedPackageName($this->getParameter('restrictedPackageName'));
$serviceMessage->setDelayWhileIdle($this->getParameter('delayWhileIdle', false));
$serviceMessage->setTimeToLive($this->getParameter('ttl', 600));
@@ -174,6 +176,7 @@ class Gcm extends BaseAdapter
{
return [
'collapseKey',
'priority',
'delayWhileIdle',
'ttl',
'restrictedPackageName',
@@ -222,7 +225,7 @@ class Gcm extends BaseAdapter
*
* @param array $config
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function setAdapterParameters(array $config = [])
{