composer-update-patch
This commit is contained in:
@@ -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'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user