composer-update-patch
This commit is contained in:
@@ -38,6 +38,13 @@ interface AdapterInterface
|
||||
*/
|
||||
public function supports($token);
|
||||
|
||||
/**
|
||||
* Get defined parameters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefinedParameters();
|
||||
|
||||
/**
|
||||
* Get default parameters.
|
||||
*
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Sly\NotificationPusher\Adapter;
|
||||
|
||||
use Sly\NotificationPusher\Model\BaseOptionedModel;
|
||||
use Sly\NotificationPusher\Model\PushInterface;
|
||||
use Sly\NotificationPusher\Model\MessageInterface;
|
||||
use Sly\NotificationPusher\Model\DeviceInterface;
|
||||
use Sly\NotificationPusher\Exception\AdapterException;
|
||||
use Sly\NotificationPusher\Exception\PushException;
|
||||
@@ -30,18 +30,24 @@ use ZendService\Apple\Apns\Client\Feedback as ServiceFeedbackClient;
|
||||
* APNS adapter.
|
||||
*
|
||||
* @uses \Sly\NotificationPusher\Adapter\BaseAdapter
|
||||
* @uses \Sly\NotificationPusher\Adapter\AdapterInterface
|
||||
*
|
||||
* @author Cédric Dugat <cedric@dugat.me>
|
||||
*/
|
||||
class Apns extends BaseAdapter implements AdapterInterface
|
||||
class Apns extends BaseAdapter
|
||||
{
|
||||
|
||||
/** @var ServiceClient */
|
||||
private $openedClient;
|
||||
|
||||
/** @var ServiceFeedbackClient */
|
||||
private $feedbackClient;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws \Sly\NotificationPusher\Exception\AdapterException
|
||||
*/
|
||||
public function __construct(array $parameters = array())
|
||||
public function __construct(array $parameters = [])
|
||||
{
|
||||
parent::__construct($parameters);
|
||||
|
||||
@@ -59,7 +65,7 @@ class Apns extends BaseAdapter implements AdapterInterface
|
||||
*/
|
||||
public function push(PushInterface $push)
|
||||
{
|
||||
$client = $this->getOpenedClient(new ServiceClient());
|
||||
$client = $this->getOpenedServiceClient();
|
||||
|
||||
$pushedDevices = new DeviceCollection();
|
||||
|
||||
@@ -77,8 +83,6 @@ class Apns extends BaseAdapter implements AdapterInterface
|
||||
}
|
||||
}
|
||||
|
||||
$client->close();
|
||||
|
||||
return $pushedDevices;
|
||||
}
|
||||
|
||||
@@ -89,13 +93,12 @@ class Apns extends BaseAdapter implements AdapterInterface
|
||||
*/
|
||||
public function getFeedback()
|
||||
{
|
||||
$client = $this->getOpenedClient(new ServiceFeedbackClient());
|
||||
$responses = array();
|
||||
$client = $this->getOpenedFeedbackClient();
|
||||
$responses = [];
|
||||
$serviceResponses = $client->feedback();
|
||||
$client->close();
|
||||
|
||||
foreach ($serviceResponses as $response) {
|
||||
$responses[$response->getToken()] = new \DateTime(date("c", $response->getTime()));
|
||||
$responses[$response->getToken()] = new \DateTime(date('c', $response->getTime()));
|
||||
}
|
||||
|
||||
return $responses;
|
||||
@@ -119,29 +122,62 @@ class Apns extends BaseAdapter implements AdapterInterface
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get opened ServiceClient
|
||||
*
|
||||
* @return ServiceAbstractClient
|
||||
*/
|
||||
private function getOpenedServiceClient()
|
||||
{
|
||||
if (!isset($this->openedClient)) {
|
||||
$this->openedClient = $this->getOpenedClient(new ServiceClient());
|
||||
}
|
||||
|
||||
return $this->openedClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get opened ServiceFeedbackClient
|
||||
*
|
||||
* @return ServiceAbstractClient
|
||||
*/
|
||||
private function getOpenedFeedbackClient()
|
||||
{
|
||||
if (!isset($this->feedbackClient)) {
|
||||
$this->feedbackClient = $this->getOpenedClient(new ServiceFeedbackClient());
|
||||
}
|
||||
|
||||
return $this->feedbackClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get service message from origin.
|
||||
*
|
||||
* @param \Sly\NotificationPusher\Model\DeviceInterface $device Device
|
||||
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
|
||||
* @param \Sly\NotificationPusher\Model\DeviceInterface $device Device
|
||||
* @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
|
||||
*
|
||||
* @return \ZendService\Apple\Apns\Message
|
||||
*/
|
||||
public function getServiceMessageFromOrigin(DeviceInterface $device, MessageInterface $message)
|
||||
public function getServiceMessageFromOrigin(DeviceInterface $device, BaseOptionedModel $message)
|
||||
{
|
||||
$badge = ($message->hasOption('badge'))
|
||||
? (int) ($message->getOption('badge') + $device->getParameter('badge', 0))
|
||||
: 0
|
||||
: false
|
||||
;
|
||||
|
||||
$sound = $message->getOption('sound', 'bingbong.aiff');
|
||||
$contentAvailable = $message->getOption('content-available');
|
||||
$category = $message->getOption('category');
|
||||
|
||||
$alert = new ServiceAlert(
|
||||
$message->getText(),
|
||||
$message->getOption('actionLocKey'),
|
||||
$message->getOption('locKey'),
|
||||
$message->getOption('locArgs'),
|
||||
$message->getOption('launchImage')
|
||||
$message->getOption('launchImage'),
|
||||
$message->getOption('title'),
|
||||
$message->getOption('titleLocKey'),
|
||||
$message->getOption('titleLocArgs')
|
||||
);
|
||||
if ($actionLocKey = $message->getOption('actionLocKey')) {
|
||||
$alert->setActionLocKey($actionLocKey);
|
||||
@@ -155,18 +191,37 @@ class Apns extends BaseAdapter implements AdapterInterface
|
||||
if ($launchImage = $message->getOption('launchImage')) {
|
||||
$alert->setLaunchImage($launchImage);
|
||||
}
|
||||
if ($title = $message->getOption('title')) {
|
||||
$alert->setTitle($title);
|
||||
}
|
||||
if ($titleLocKey = $message->getOption('titleLocKey')) {
|
||||
$alert->setTitleLocKey($titleLocKey);
|
||||
}
|
||||
if ($titleLocArgs = $message->getOption('titleLocArgs')) {
|
||||
$alert->setTitleLocArgs($titleLocArgs);
|
||||
}
|
||||
|
||||
$serviceMessage = new ServiceMessage();
|
||||
$serviceMessage->setId(sha1($device->getToken().$message->getText()));
|
||||
$serviceMessage->setAlert($alert);
|
||||
$serviceMessage->setToken($device->getToken());
|
||||
$serviceMessage->setBadge($badge);
|
||||
$serviceMessage->setCustom($message->getOption('custom', array()));
|
||||
if (false !== $badge) {
|
||||
$serviceMessage->setBadge($badge);
|
||||
}
|
||||
$serviceMessage->setCustom($message->getOption('custom', []));
|
||||
|
||||
if (null !== $sound) {
|
||||
$serviceMessage->setSound($sound);
|
||||
}
|
||||
|
||||
if (null !== $contentAvailable) {
|
||||
$serviceMessage->setContentAvailable($contentAvailable);
|
||||
}
|
||||
|
||||
if (null !== $category) {
|
||||
$serviceMessage->setCategory($category);
|
||||
}
|
||||
|
||||
return $serviceMessage;
|
||||
}
|
||||
|
||||
@@ -178,12 +233,20 @@ class Apns extends BaseAdapter implements AdapterInterface
|
||||
return (ctype_xdigit($token) && 64 == strlen($token));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefinedParameters()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultParameters()
|
||||
{
|
||||
return array('passPhrase' => null);
|
||||
return ['passPhrase' => null];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,6 +254,6 @@ class Apns extends BaseAdapter implements AdapterInterface
|
||||
*/
|
||||
public function getRequiredParameters()
|
||||
{
|
||||
return array('certificate');
|
||||
return ['certificate'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use Sly\NotificationPusher\PushManager;
|
||||
*
|
||||
* @author Cédric Dugat <cedric@dugat.me>
|
||||
*/
|
||||
abstract class BaseAdapter extends BaseParameteredModel
|
||||
abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
@@ -43,9 +43,10 @@ abstract class BaseAdapter extends BaseParameteredModel
|
||||
*
|
||||
* @param array $parameters Adapter specific parameters
|
||||
*/
|
||||
public function __construct(array $parameters = array())
|
||||
public function __construct(array $parameters = [])
|
||||
{
|
||||
$resolver = new OptionsResolver();
|
||||
$resolver->setDefined($this->getDefinedParameters());
|
||||
$resolver->setDefaults($this->getDefaultParameters());
|
||||
$resolver->setRequired($this->getRequiredParameters());
|
||||
|
||||
@@ -66,7 +67,7 @@ abstract class BaseAdapter extends BaseParameteredModel
|
||||
|
||||
/**
|
||||
* Return the original response.
|
||||
*
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResponse()
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Sly\NotificationPusher\Adapter;
|
||||
|
||||
use Sly\NotificationPusher\Model\BaseOptionedModel;
|
||||
use Sly\NotificationPusher\Model\PushInterface;
|
||||
use Sly\NotificationPusher\Model\MessageInterface;
|
||||
use Sly\NotificationPusher\Collection\DeviceCollection;
|
||||
use Sly\NotificationPusher\Exception\PushException;
|
||||
|
||||
@@ -29,23 +29,27 @@ use InvalidArgumentException;
|
||||
* GCM adapter.
|
||||
*
|
||||
* @uses \Sly\NotificationPusher\Adapter\BaseAdapter
|
||||
* @uses \Sly\NotificationPusher\Adapter\AdapterInterface
|
||||
*
|
||||
* @author Cédric Dugat <cedric@dugat.me>
|
||||
*/
|
||||
class Gcm extends BaseAdapter implements AdapterInterface
|
||||
class Gcm extends BaseAdapter
|
||||
{
|
||||
/**
|
||||
* @var \Zend\Http\Client
|
||||
*/
|
||||
private $httpClient;
|
||||
|
||||
|
||||
/**
|
||||
* @var ServiceClient
|
||||
*/
|
||||
private $openedClient;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($token)
|
||||
{
|
||||
return (bool) preg_match('/[0-9a-zA-Z\-\_]/i', $token);
|
||||
return is_string($token) && $token != '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +59,7 @@ class Gcm extends BaseAdapter implements AdapterInterface
|
||||
*/
|
||||
public function push(PushInterface $push)
|
||||
{
|
||||
$client = $this->getOpenedClient(new ServiceClient());
|
||||
$client = $this->getOpenedClient();
|
||||
$pushedDevices = new DeviceCollection();
|
||||
$tokens = array_chunk($push->getDevices()->getTokens(), 100);
|
||||
|
||||
@@ -81,30 +85,37 @@ class Gcm extends BaseAdapter implements AdapterInterface
|
||||
/**
|
||||
* Get opened client.
|
||||
*
|
||||
* @param \ZendService\Google\Gcm\Client $client Client
|
||||
*
|
||||
* @return \ZendService\Google\Gcm\Client
|
||||
*/
|
||||
public function getOpenedClient(ServiceClient $client)
|
||||
public function getOpenedClient()
|
||||
{
|
||||
$client->setApiKey($this->getParameter('apiKey'));
|
||||
|
||||
if ($this->httpClient !== null) {
|
||||
$client->setHttpClient($this->httpClient);
|
||||
if (!isset($this->openedClient)) {
|
||||
$this->openedClient = new ServiceClient();
|
||||
$this->openedClient->setApiKey($this->getParameter('apiKey'));
|
||||
|
||||
$newClient = new \Zend\Http\Client(
|
||||
null,
|
||||
[
|
||||
'adapter' => 'Zend\Http\Client\Adapter\Socket',
|
||||
'sslverifypeer' => false
|
||||
]
|
||||
);
|
||||
|
||||
$this->openedClient->setHttpClient($newClient);
|
||||
}
|
||||
|
||||
return $client;
|
||||
return $this->openedClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get service message from origin.
|
||||
*
|
||||
* @param array $tokens Tokens
|
||||
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
|
||||
* @param array $tokens Tokens
|
||||
* @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
|
||||
*
|
||||
* @return \ZendService\Google\Gcm\Message
|
||||
*/
|
||||
public function getServiceMessageFromOrigin(array $tokens, MessageInterface $message)
|
||||
public function getServiceMessageFromOrigin(array $tokens, BaseOptionedModel $message)
|
||||
{
|
||||
$data = $message->getOptions();
|
||||
$data['message'] = $message->getText();
|
||||
@@ -121,12 +132,26 @@ class Gcm extends BaseAdapter implements AdapterInterface
|
||||
return $serviceMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefinedParameters()
|
||||
{
|
||||
return [
|
||||
'collapse_key',
|
||||
'delay_while_idle',
|
||||
'time_to_live',
|
||||
'restricted_package_name',
|
||||
'dry_run'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultParameters()
|
||||
{
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,10 +159,9 @@ class Gcm extends BaseAdapter implements AdapterInterface
|
||||
*/
|
||||
public function getRequiredParameters()
|
||||
{
|
||||
return array('apiKey');
|
||||
return ['apiKey'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current Zend Http Client instance.
|
||||
*
|
||||
@@ -150,7 +174,7 @@ class Gcm extends BaseAdapter implements AdapterInterface
|
||||
|
||||
/**
|
||||
* Overrides the default Http Client.
|
||||
*
|
||||
*
|
||||
* @param HttpClient $client
|
||||
*/
|
||||
public function setHttpClient(HttpClient $client)
|
||||
@@ -160,12 +184,12 @@ class Gcm extends BaseAdapter implements AdapterInterface
|
||||
|
||||
/**
|
||||
* Send custom parameters to the Http Adapter without overriding the Http Client.
|
||||
*
|
||||
*
|
||||
* @param array $config
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setAdapterParameters(array $config = array())
|
||||
public function setAdapterParameters(array $config = [])
|
||||
{
|
||||
if (!is_array($config) || empty($config)) {
|
||||
throw new InvalidArgumentException('$config must be an associative array with at least 1 item.');
|
||||
|
||||
Reference in New Issue
Block a user