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,6 +11,9 @@ namespace Sly\NotificationPusher;
use Sly\NotificationPusher\Model\ResponseInterface;
/**
* @author Oleg Abrazhaev <seyferseed@gmail.com>
*/
abstract class AbstractPushService
{
/**
@@ -24,7 +27,6 @@ abstract class AbstractPushService
protected $response;
/**
* AbstractPushService constructor.
* @param string $environment
*/
public function __construct($environment = PushManager::ENVIRONMENT_DEV)
@@ -39,4 +41,4 @@ abstract class AbstractPushService
{
return $this->response;
}
}
}

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 = [])
{

View File

@@ -17,10 +17,8 @@ use Sly\NotificationPusher\Model\ResponseInterface;
use Symfony\Component\Filesystem\Filesystem;
/**
* Facade for simple use cases
*
* Class ApnsPushService
* @package Sly\NotificationPusher
* @author Oleg Abrazhaev <seyferseed@gmail.com>
*/
class ApnsPushService extends AbstractPushService
{
@@ -50,7 +48,7 @@ class ApnsPushService extends AbstractPushService
parent::__construct($environment);
$this->certificatePath = $certificatePath;
$this->passPhrase = $passPhrase;
$this->passPhrase = $passPhrase;
}
/**
@@ -75,7 +73,7 @@ class ApnsPushService extends AbstractPushService
}
$adapterParams = [];
$deviceParams = [];
$deviceParams = [];
$messageParams = [];
if (isset($params) && !empty($params)) {
if (isset($params['adapter'])) {
@@ -92,10 +90,9 @@ class ApnsPushService extends AbstractPushService
}
$adapterParams['certificate'] = $this->certificatePath;
$adapterParams['passPhrase'] = $this->passPhrase;
$adapterParams['passPhrase'] = $this->passPhrase;
// Development one by default (without argument).
/** @var PushManager $pushManager */
$pushManager = new PushManager($this->environment);
// Then declare an adapter.
@@ -135,9 +132,9 @@ class ApnsPushService extends AbstractPushService
*/
public function feedback()
{
$adapterParams = [];
$adapterParams = [];
$adapterParams['certificate'] = $this->certificatePath;
$adapterParams['passPhrase'] = $this->passPhrase;
$adapterParams['passPhrase'] = $this->passPhrase;
// Development one by default (without argument).
/** @var PushManager $pushManager */
@@ -201,7 +198,7 @@ class ApnsPushService extends AbstractPushService
}
$feedbackTokens = array_keys($this->feedback);
$sentTokens = array_keys($this->response->getParsedResponses());
$sentTokens = array_keys($this->response->getParsedResponses());
//all bad
if (!$feedbackTokens) {

View File

@@ -11,31 +11,33 @@
namespace Sly\NotificationPusher\Collection;
use ArrayIterator;
use Countable;
use IteratorAggregate;
use SeekableIterator;
use Sly\NotificationPusher\Model\MessageInterface;
/**
* AbstractCollection.
*
* @uses \IteratorAggregate
* @author Cédric Dugat <cedric@dugat.me>
*/
abstract class AbstractCollection implements \IteratorAggregate, \Countable
abstract class AbstractCollection implements IteratorAggregate, Countable
{
/**
* @var \ArrayIterator
* @var ArrayIterator
*/
protected $coll;
/**
* @inheritdoc
* @return \ArrayIterator|\SeekableIterator
* @return ArrayIterator|SeekableIterator
*/
abstract public function getIterator();
/**
* Get.
*
* @param string $key Key
*
* @return \Sly\NotificationPusher\Model\MessageInterface|false
* @return MessageInterface|false
*/
public function get($key)
{
@@ -43,8 +45,6 @@ abstract class AbstractCollection implements \IteratorAggregate, \Countable
}
/**
* Count.
*
* @return integer
*/
public function count()
@@ -53,8 +53,6 @@ abstract class AbstractCollection implements \IteratorAggregate, \Countable
}
/**
* isEmpty.
*
* @return boolean
*/
public function isEmpty()
@@ -67,7 +65,7 @@ abstract class AbstractCollection implements \IteratorAggregate, \Countable
*/
public function clear()
{
$this->coll = new \ArrayIterator();
$this->coll = new ArrayIterator();
}
/**

View File

@@ -14,17 +14,13 @@ namespace Sly\NotificationPusher\Collection;
use Sly\NotificationPusher\Model\DeviceInterface;
/**
* DeviceCollection.
*
* @uses \Sly\NotificationPusher\Collection\AbstractCollection
* @uses \IteratorAggregate
* @author Cédric Dugat <cedric@dugat.me>
*/
class DeviceCollection extends AbstractCollection implements \IteratorAggregate
class DeviceCollection extends AbstractCollection
{
/**
* Constructor.
*
* @param array $devices Devices
*/
public function __construct(array $devices = [])
@@ -45,7 +41,7 @@ class DeviceCollection extends AbstractCollection implements \IteratorAggregate
}
/**
* @param \Sly\NotificationPusher\Model\DeviceInterface $device Device
* @param DeviceInterface $device Device
*/
public function add(DeviceInterface $device)
{
@@ -53,8 +49,6 @@ class DeviceCollection extends AbstractCollection implements \IteratorAggregate
}
/**
* Get tokens.
*
* @return array
*/
public function getTokens()

View File

@@ -14,17 +14,12 @@ namespace Sly\NotificationPusher\Collection;
use Sly\NotificationPusher\Model\MessageInterface;
/**
* MessageCollection.
*
* @uses \Sly\NotificationPusher\Collection\AbstractCollection
* @uses \IteratorAggregate
* @author Cédric Dugat <cedric@dugat.me>
*/
class MessageCollection extends AbstractCollection implements \IteratorAggregate
class MessageCollection extends AbstractCollection
{
/**
* Constructor.
*/
public function __construct()
{
$this->coll = new \ArrayIterator();
@@ -39,7 +34,7 @@ class MessageCollection extends AbstractCollection implements \IteratorAggregate
}
/**
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
* @param MessageInterface $message Message
*/
public function add(MessageInterface $message)
{

View File

@@ -14,17 +14,12 @@ namespace Sly\NotificationPusher\Collection;
use Sly\NotificationPusher\Model\PushInterface;
/**
* PushCollection.
*
* @uses \Sly\NotificationPusher\Collection\AbstractCollection
* @uses \IteratorAggregate
* @author Cédric Dugat <cedric@dugat.me>
*/
class PushCollection extends AbstractCollection
{
/**
* Constructor.
*/
public function __construct()
{
$this->coll = new \ArrayIterator();
@@ -39,7 +34,7 @@ class PushCollection extends AbstractCollection
}
/**
* @param \Sly\NotificationPusher\Model\PushInterface $push Push
* @param PushInterface $push Push
*/
public function add(PushInterface $push)
{

View File

@@ -22,9 +22,6 @@ namespace Sly\NotificationPusher\Collection;
*/
class ResponseCollection extends AbstractCollection
{
/**
* Constructor.
*/
public function __construct()
{
$this->coll = new \ArrayIterator();

View File

@@ -16,16 +16,11 @@ use Sly\NotificationPusher\NotificationPusher;
use Symfony\Component\Console\Application as BaseApplication;
/**
* Application.
*
* @uses \Symfony\Component\Console\Application
* @author Cédric Dugat <cedric@dugat.me>
*/
class Application extends BaseApplication
{
/**
* Constructor.
*/
public function __construct()
{
error_reporting(-1);

View File

@@ -12,6 +12,8 @@
namespace Sly\NotificationPusher\Console\Command;
use Doctrine\Common\Inflector\Inflector;
use Exception;
use Sly\NotificationPusher\Adapter\AdapterInterface;
use Sly\NotificationPusher\Exception\AdapterException;
use Sly\NotificationPusher\Model\Device;
use Sly\NotificationPusher\Model\Message;
@@ -24,8 +26,6 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* PushCommand.
*
* @uses \Symfony\Component\Console\Command\Command
* @author Cédric Dugat <cedric@dugat.me>
*/
@@ -85,18 +85,16 @@ class PushCommand extends Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$adapter = $this->getReadyAdapter($input, $output);
$adapter = $this->getReadyAdapter($input, $output);
$pushManager = new PushManager($input->getOption('env'));
$message = new Message($input->getArgument('message'));
$push = new Push($adapter, new Device($input->getArgument('token')), $message);
$message = new Message($input->getArgument('message'));
$push = new Push($adapter, new Device($input->getArgument('token')), $message);
$pushManager->add($push);
$pushManager->push();
}
/**
* Get adapter class from argument.
*
* @param string $argument Given argument
*
* @return string
@@ -121,7 +119,7 @@ class PushCommand extends Command
/**
* {@inheritdoc}
*
* @return \Sly\NotificationPusher\Adapter\AdapterInterface
* @return AdapterInterface
*/
private function getReadyAdapter(InputInterface $input, OutputInterface $output)
{
@@ -129,13 +127,13 @@ class PushCommand extends Command
try {
$adapter = new $adapterClass();
} catch (\Exception $e) {
} catch (Exception $e) {
$adapterData = [];
preg_match_all('/"(.*)"/i', $e->getMessage(), $matches);
foreach ($matches[1] as $match) {
$optionKey = str_replace('_', '-', Inflector::tableize($match));
$option = $input->getOption($optionKey);
$option = $input->getOption($optionKey);
if (!$option) {
throw new AdapterException(

View File

@@ -12,8 +12,6 @@
namespace Sly\NotificationPusher\Exception;
/**
* AdapterException.
*
* @uses \RuntimeException
* @uses \Sly\NotificationPusher\Exception\ExceptionInterface
*

View File

@@ -12,8 +12,6 @@
namespace Sly\NotificationPusher\Exception;
/**
* ExceptionInterface.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
interface ExceptionInterface

View File

@@ -12,8 +12,6 @@
namespace Sly\NotificationPusher\Exception;
/**
* InvalidException.
*
* @uses \RuntimeException
* @uses \Sly\NotificationPusher\Exception\ExceptionInterface
*

View File

@@ -12,8 +12,6 @@
namespace Sly\NotificationPusher\Exception;
/**
* PushException.
*
* @uses \RuntimeException
* @uses \Sly\NotificationPusher\Exception\ExceptionInterface
*

View File

@@ -12,8 +12,6 @@
namespace Sly\NotificationPusher\Exception;
/**
* RuntimeException.
*
* @uses \RuntimeException
* @uses \Sly\NotificationPusher\Exception\ExceptionInterface
*

View File

@@ -20,6 +20,7 @@ use Sly\NotificationPusher\Model\ResponseInterface;
*
* Class GcmPushService
* @package Sly\NotificationPusher
* @author Oleg Abrazhaev <seyferseed@gmail.com>
*/
class GcmPushService extends AbstractPushService
{
@@ -29,7 +30,6 @@ class GcmPushService extends AbstractPushService
private $apiKey = '';
/**
* GcmPushService constructor.
* @param string $environment
* @param string $apiKey
*/
@@ -58,7 +58,7 @@ class GcmPushService extends AbstractPushService
}
$adapterParams = [];
$deviceParams = [];
$deviceParams = [];
$messageParams = [];
if (isset($params) && !empty($params)) {
if (isset($params['adapter'])) {
@@ -86,7 +86,6 @@ class GcmPushService extends AbstractPushService
}
// Development one by default (without argument).
/** @var PushManager $pushManager */
$pushManager = new PushManager($this->environment);
// Then declare an adapter.
@@ -130,7 +129,7 @@ class GcmPushService extends AbstractPushService
foreach ($this->response->getParsedResponses() as $token => $response) {
if (array_key_exists('error', $response) && !array_key_exists('message_id', $response)) {
array_push($tokens, $token);
$tokens[] = $token;
}
}
@@ -150,7 +149,7 @@ class GcmPushService extends AbstractPushService
foreach ($this->response->getParsedResponses() as $token => $response) {
if (!array_key_exists('error', $response) && array_key_exists('message_id', $response)) {
array_push($tokens, $token);
$tokens[] = $token;
}
}

View File

@@ -12,8 +12,6 @@
namespace Sly\NotificationPusher\Model;
/**
* BaseOptionedModel.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
abstract class BaseOptionedModel
@@ -24,8 +22,6 @@ abstract class BaseOptionedModel
protected $options = [];
/**
* Get options.
*
* @return array
*/
public function getOptions()
@@ -34,8 +30,6 @@ abstract class BaseOptionedModel
}
/**
* Has option.
*
* @param string $key Key
*
* @return boolean
@@ -46,8 +40,6 @@ abstract class BaseOptionedModel
}
/**
* Get option.
*
* @param string $key Key
* @param mixed $default Default
*
@@ -59,11 +51,9 @@ abstract class BaseOptionedModel
}
/**
* Set options.
*
* @param array $options Options
*
* @return \Sly\NotificationPusher\Model\BaseOptionedModel
* @return BaseOptionedModel
*/
public function setOptions($options)
{
@@ -73,8 +63,6 @@ abstract class BaseOptionedModel
}
/**
* Set option.
*
* @param string $key Key
* @param mixed $value Value
*

View File

@@ -12,8 +12,6 @@
namespace Sly\NotificationPusher\Model;
/**
* BaseParameteredModel.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
abstract class BaseParameteredModel
@@ -24,8 +22,6 @@ abstract class BaseParameteredModel
protected $parameters = [];
/**
* Get parameters.
*
* @return array
*/
public function getParameters()
@@ -34,8 +30,6 @@ abstract class BaseParameteredModel
}
/**
* Has parameter.
*
* @param string $key Key
*
* @return boolean
@@ -46,8 +40,6 @@ abstract class BaseParameteredModel
}
/**
* Get parameter.
*
* @param string $key Key
* @param mixed $default Default
*
@@ -59,11 +51,9 @@ abstract class BaseParameteredModel
}
/**
* Set parameters.
*
* @param array $parameters Parameters
*
* @return \Sly\NotificationPusher\Model\BaseParameteredModel
* @return BaseParameteredModel
*/
public function setParameters($parameters)
{
@@ -73,8 +63,6 @@ abstract class BaseParameteredModel
}
/**
* Set parameter.
*
* @param string $key Key
* @param mixed $value Value
*

View File

@@ -12,8 +12,6 @@
namespace Sly\NotificationPusher\Model;
/**
* Device.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
class Device extends BaseParameteredModel implements DeviceInterface
@@ -24,20 +22,16 @@ class Device extends BaseParameteredModel implements DeviceInterface
private $token;
/**
* Constructor.
*
* @param string $token Token
* @param array $parameters Parameters
*/
public function __construct($token, array $parameters = [])
{
$this->token = $token;
$this->token = $token;
$this->parameters = $parameters;
}
/**
* Get token.
*
* @return string
*/
public function getToken()
@@ -46,11 +40,9 @@ class Device extends BaseParameteredModel implements DeviceInterface
}
/**
* Set token.
*
* @param string $token Token
*
* @return \Sly\NotificationPusher\Model\DeviceInterface
* @return DeviceInterface
*/
public function setToken($token)
{

View File

@@ -12,25 +12,19 @@
namespace Sly\NotificationPusher\Model;
/**
* DeviceInterface
*
* @author Cédric Dugat <cedric@dugat.me>
*/
interface DeviceInterface
{
/**
* Get token.
*
* @return string
*/
public function getToken();
/**
* Set token.
*
* @param string $token Token
*
* @return \Sly\NotificationPusher\Model\DeviceInterface
* @return DeviceInterface
*/
public function setToken($token);
}

View File

@@ -12,8 +12,6 @@
namespace Sly\NotificationPusher\Model;
/**
* Message.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
class Message extends BaseOptionedModel implements MessageInterface
@@ -24,20 +22,16 @@ class Message extends BaseOptionedModel implements MessageInterface
protected $text;
/**
* Constructor.
*
* @param string $text Text
* @param array $options Options
*/
public function __construct($text, array $options = [])
{
$this->text = $text;
$this->text = $text;
$this->options = $options;
}
/**
* Get Text.
*
* @return string
*/
public function getText()
@@ -46,11 +40,9 @@ class Message extends BaseOptionedModel implements MessageInterface
}
/**
* Set Text.
*
* @param string $text Text
*
* @return \Sly\NotificationPusher\Model\MessageInterface
* @return MessageInterface
*/
public function setText($text)
{

View File

@@ -12,25 +12,19 @@
namespace Sly\NotificationPusher\Model;
/**
* MessageInterface
*
* @author Cédric Dugat <cedric@dugat.me>
*/
interface MessageInterface
{
/**
* Get Text.
*
* @return string
*/
public function getText();
/**
* Set Text.
*
* @param string $text Text
*
* @return \Sly\NotificationPusher\Model\MessageInterface
* @return MessageInterface
*/
public function setText($text);
}

View File

@@ -17,8 +17,6 @@ use Sly\NotificationPusher\Collection\ResponseCollection;
use Sly\NotificationPusher\Exception\AdapterException;
/**
* Push.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
class Push extends BaseOptionedModel implements PushInterface
@@ -30,17 +28,17 @@ class Push extends BaseOptionedModel implements PushInterface
private $status;
/**
* @var \Sly\NotificationPusher\Adapter\AdapterInterface
* @var AdapterInterface
*/
private $adapter;
/**
* @var \Sly\NotificationPusher\Model\MessageInterface
* @var MessageInterface
*/
private $message;
/**
* @var \Sly\NotificationPusher\Collection\DeviceCollection
* @var DeviceCollection
*/
private $devices;
@@ -50,22 +48,20 @@ class Push extends BaseOptionedModel implements PushInterface
private $pushedAt;
/**
* @var \Sly\NotificationPusher\Collection\ResponseCollection
* @var ResponseCollection
*/
private $responses;
/**
* Constructor.
*
* @param \Sly\NotificationPusher\Adapter\AdapterInterface $adapter Adapter
* @param AdapterInterface $adapter Adapter
* @param DeviceInterface|DeviceCollection $devices Device(s)
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
* @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 \Sly\NotificationPusher\Exception\AdapterException
* @throws AdapterException
*/
public function __construct(AdapterInterface $adapter, $devices, MessageInterface $message, array $options = [])
{
@@ -77,14 +73,13 @@ class Push extends BaseOptionedModel implements PushInterface
$this->devices = $devices;
$this->message = $message;
$this->options = $options;
$this->status = self::STATUS_PENDING;
$this->status = self::STATUS_PENDING;
$this->checkDevicesTokens();
}
/**
* Check devices tokens.
* @throws \Sly\NotificationPusher\Exception\AdapterException
* @throws AdapterException
*/
private function checkDevicesTokens()
{
@@ -96,7 +91,7 @@ class Push extends BaseOptionedModel implements PushInterface
throw new AdapterException(
sprintf(
'Adapter %s does not support %s token\'s device',
(string)$adapter,
(string) $adapter,
$device->getToken()
)
);
@@ -105,8 +100,6 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Get Status.
*
* @return string
*/
public function getStatus()
@@ -115,11 +108,9 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Set Status.
*
* @param string $status Status
*
* @return \Sly\NotificationPusher\Model\PushInterface
* @return PushInterface
*/
public function setStatus($status)
{
@@ -129,32 +120,26 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* isPushed.
*
* @return boolean
*/
public function isPushed()
{
return (bool)(self::STATUS_PUSHED === $this->status);
return (bool) (self::STATUS_PUSHED === $this->status);
}
/**
* Declare as pushed.
*
* @return \Sly\NotificationPusher\Model\PushInterface
* @return PushInterface
*/
public function pushed()
{
$this->status = self::STATUS_PUSHED;
$this->status = self::STATUS_PUSHED;
$this->pushedAt = new \DateTime();
return $this;
}
/**
* Get Adapter.
*
* @return \Sly\NotificationPusher\Adapter\AdapterInterface
* @return AdapterInterface
*/
public function getAdapter()
{
@@ -162,11 +147,9 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Set Adapter.
* @param AdapterInterface $adapter Adapter
*
* @param \Sly\NotificationPusher\Adapter\AdapterInterface $adapter Adapter
*
* @return \Sly\NotificationPusher\Model\PushInterface
* @return PushInterface
*/
public function setAdapter(AdapterInterface $adapter)
{
@@ -176,9 +159,7 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Get Message.
*
* @return \Sly\NotificationPusher\Model\MessageInterface
* @return MessageInterface
*/
public function getMessage()
{
@@ -186,11 +167,9 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Set Message.
* @param MessageInterface $message Message
*
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
*
* @return \Sly\NotificationPusher\Model\PushInterface
* @return PushInterface
*/
public function setMessage(MessageInterface $message)
{
@@ -200,9 +179,7 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Get Devices.
*
* @return \Sly\NotificationPusher\Collection\DeviceCollection
* @return DeviceCollection
*/
public function getDevices()
{
@@ -210,11 +187,9 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Set Devices.
* @param DeviceCollection $devices Devices
*
* @param \Sly\NotificationPusher\Collection\DeviceCollection $devices Devices
*
* @return \Sly\NotificationPusher\Model\PushInterface
* @return PushInterface
*/
public function setDevices(DeviceCollection $devices)
{
@@ -226,8 +201,7 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Get Responses
* @return \Sly\NotificationPusher\Collection\ResponseCollection
* @return ResponseCollection
*/
public function getResponses()
{
@@ -238,8 +212,7 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* adds a response
* @param \Sly\NotificationPusher\Model\DeviceInterface $device
* @param DeviceInterface $device
* @param mixed $response
*/
public function addResponse(DeviceInterface $device, $response)
@@ -248,8 +221,6 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Get PushedAt.
*
* @return \DateTime
*/
public function getPushedAt()
@@ -258,11 +229,9 @@ class Push extends BaseOptionedModel implements PushInterface
}
/**
* Set PushedAt.
*
* @param \DateTime $pushedAt PushedAt
*
* @return \Sly\NotificationPusher\Model\PushInterface
* @return PushInterface
*/
public function setPushedAt(\DateTime $pushedAt)
{

View File

@@ -14,28 +14,22 @@ namespace Sly\NotificationPusher\Model;
use DateTime;
use Sly\NotificationPusher\Adapter\AdapterInterface;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Collection\ResponseCollection;
/**
* PushInterface
*/
interface PushInterface
{
/**
* Constants define available statuses
*/
const STATUS_PENDING = 'pending';
const STATUS_PUSHED = 'sent';
const STATUS_PUSHED = 'sent';
/**
* Get Status.
*
* @return string
*/
public function getStatus();
/**
* Set Status.
*
* @param string $status Status
*
* @return PushInterface
@@ -43,29 +37,21 @@ interface PushInterface
public function setStatus($status);
/**
* isPushed.
*
* @return boolean
*/
public function isPushed();
/**
* Declare as pushed.
*
* @return PushInterface
*/
public function pushed();
/**
* Get Adapter.
*
* @return AdapterInterface
*/
public function getAdapter();
/**
* Set Adapter.
*
* @param AdapterInterface $adapter Adapter
*
* @return PushInterface
@@ -73,15 +59,11 @@ interface PushInterface
public function setAdapter(AdapterInterface $adapter);
/**
* Get Message.
*
* @return MessageInterface
*/
public function getMessage();
/**
* Set Message.
*
* @param MessageInterface $message Message
*
* @return PushInterface
@@ -89,15 +71,11 @@ interface PushInterface
public function setMessage(MessageInterface $message);
/**
* Get Devices.
*
* @return DeviceCollection
*/
public function getDevices();
/**
* Set Devices.
*
* @param DeviceCollection $devices Devices
*
* @return PushInterface
@@ -105,28 +83,22 @@ interface PushInterface
public function setDevices(DeviceCollection $devices);
/**
* Get Responses
* @return \Sly\NotificationPusher\Collection\ResponseCollection
* @return ResponseCollection
*/
public function getResponses();
/**
* adds a response
* @param \Sly\NotificationPusher\Model\DeviceInterface $device
* @param DeviceInterface $device
* @param mixed $response
*/
public function addResponse(DeviceInterface $device, $response);
/**
* Get PushedAt.
*
* @return DateTime
*/
public function getPushedAt();
/**
* Set PushedAt.
*
* @param DateTime $pushedAt PushedAt
*
* @return PushInterface

View File

@@ -11,6 +11,9 @@ namespace Sly\NotificationPusher\Model;
use Sly\NotificationPusher\Collection\PushCollection;
/**
* @author Oleg Abrazhaev <seyferseed@gmail.com>
*/
class Response implements ResponseInterface
{
/**
@@ -28,9 +31,6 @@ class Response implements ResponseInterface
*/
private $pushCollection;
/**
* Response constructor.
*/
public function __construct()
{
$this->pushCollection = new PushCollection();
@@ -59,7 +59,7 @@ class Response implements ResponseInterface
}
/**
* @param \Sly\NotificationPusher\Model\PushInterface $push Push
* @param PushInterface $push Push
*/
public function addPush(PushInterface $push)
{
@@ -89,4 +89,4 @@ class Response implements ResponseInterface
{
return $this->pushCollection;
}
}
}

View File

@@ -10,6 +10,9 @@ namespace Sly\NotificationPusher\Model;
use Sly\NotificationPusher\Collection\PushCollection;
/**
* @author Oleg Abrazhaev <seyferseed@gmail.com>
*/
interface ResponseInterface
{
/**
@@ -25,7 +28,7 @@ interface ResponseInterface
public function addOriginalResponse(DeviceInterface $device, $originalResponse);
/**
* @param \Sly\NotificationPusher\Model\PushInterface $push Push
* @param PushInterface $push Push
*/
public function addPush(PushInterface $push);
@@ -43,4 +46,4 @@ interface ResponseInterface
* @return PushCollection
*/
public function getPushCollection();
}
}

View File

@@ -11,9 +11,6 @@
namespace Sly\NotificationPusher;
/**
* NotificationPusher.
*/
class NotificationPusher
{
const VERSION = '2.0';

View File

@@ -20,14 +20,12 @@ use Sly\NotificationPusher\Model\PushInterface;
use Sly\NotificationPusher\Model\ResponseInterface;
/**
* PushManager.
*
* @uses \Sly\NotificationPusher\Collection\PushCollection
* @author Cédric Dugat <cedric@dugat.me>
*/
class PushManager
{
const ENVIRONMENT_DEV = 'dev';
const ENVIRONMENT_DEV = 'dev';
const ENVIRONMENT_PROD = 'prod';
/**
@@ -46,18 +44,16 @@ class PushManager
private $response;
/**
* Constructor.
*
* @param string $environment Environment
*/
public function __construct($environment = self::ENVIRONMENT_DEV)
{
$this->environment = $environment;
$this->environment = $environment;
$this->pushCollection = new PushCollection();
}
/**
* @param \Sly\NotificationPusher\Model\PushInterface $push Push
* @param PushInterface $push Push
*/
public function add(PushInterface $push)
{
@@ -65,8 +61,6 @@ class PushManager
}
/**
* Get environment.
*
* @return string
*/
public function getEnvironment()
@@ -75,8 +69,6 @@ class PushManager
}
/**
* Push.
*
* @return PushCollection
*/
public function push()
@@ -93,17 +85,15 @@ class PushManager
if ($this->pushCollection && !$this->pushCollection->isEmpty()) {
/** @var Push $push */
$push = $this->pushCollection->first();
$push = $this->pushCollection->first();
$this->response = $push->getAdapter()->getResponse();
}
return $this->pushCollection;
}
/**
* Get feedback.
*
* @param \Sly\NotificationPusher\Adapter\AdapterInterface $adapter Adapter
* @param AdapterInterface $adapter Adapter
*
* @return array
*
@@ -115,7 +105,7 @@ class PushManager
throw new AdapterException(
sprintf(
'%s adapter has no dedicated "getFeedback" method',
(string)$adapter
(string) $adapter
)
);
}