update v1.0.7.9 R.C.
This is a Release Candidate. We are still testing.
This commit is contained in:
207
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Client/AbstractClient.php
vendored
Normal file
207
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Client/AbstractClient.php
vendored
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @package Zend_Service
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Apns\Client;
|
||||
|
||||
use ZendService\Apple\Exception;
|
||||
use ZendService\Apple\Exception\StreamSocketClientException;
|
||||
|
||||
/**
|
||||
* Apple Push Notification Abstract Client
|
||||
*/
|
||||
abstract class AbstractClient
|
||||
{
|
||||
/**
|
||||
* APNS URI Constants
|
||||
* @var int
|
||||
*/
|
||||
const SANDBOX_URI = 0;
|
||||
const PRODUCTION_URI = 1;
|
||||
|
||||
/**
|
||||
* APNS URIs
|
||||
* @var array
|
||||
*/
|
||||
protected $uris = array();
|
||||
|
||||
/**
|
||||
* Is Connected
|
||||
* @var boolean
|
||||
*/
|
||||
protected $isConnected = false;
|
||||
|
||||
/**
|
||||
* Stream Socket
|
||||
* @var Resource
|
||||
*/
|
||||
protected $socket;
|
||||
|
||||
/**
|
||||
* Open Connection to APNS Service
|
||||
*
|
||||
* @param int $environment
|
||||
* @param string $certificate
|
||||
* @param string $passPhrase
|
||||
* @throws Exception\RuntimeException
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return AbstractClient
|
||||
*/
|
||||
public function open($environment, $certificate, $passPhrase = null)
|
||||
{
|
||||
if ($this->isConnected) {
|
||||
throw new Exception\RuntimeException('Connection has already been opened and must be closed');
|
||||
}
|
||||
|
||||
if (!array_key_exists($environment, $this->uris)) {
|
||||
throw new Exception\InvalidArgumentException('Environment must be one of PRODUCTION_URI or SANDBOX_URI');
|
||||
}
|
||||
|
||||
if (!is_string($certificate) || !file_exists($certificate)) {
|
||||
throw new Exception\InvalidArgumentException('Certificate must be a valid path to a APNS certificate');
|
||||
}
|
||||
|
||||
$sslOptions = array(
|
||||
'local_cert' => $certificate,
|
||||
);
|
||||
if ($passPhrase !== null) {
|
||||
if (!is_scalar($passPhrase)) {
|
||||
throw new Exception\InvalidArgumentException('SSL passphrase must be a scalar');
|
||||
}
|
||||
$sslOptions['passphrase'] = $passPhrase;
|
||||
}
|
||||
$this->connect($this->uris[$environment], $sslOptions);
|
||||
$this->isConnected = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to Host
|
||||
*
|
||||
* @param string $host
|
||||
* @param array $ssl
|
||||
* @return AbstractClient
|
||||
*/
|
||||
protected function connect($host, array $ssl)
|
||||
{
|
||||
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
||||
throw new StreamSocketClientException($errstr, $errno, 1, $errfile, $errline);
|
||||
});
|
||||
|
||||
try {
|
||||
$this->socket = stream_socket_client(
|
||||
$host,
|
||||
$errno,
|
||||
$errstr,
|
||||
ini_get('default_socket_timeout'),
|
||||
STREAM_CLIENT_CONNECT,
|
||||
stream_context_create(
|
||||
array(
|
||||
'ssl' => $ssl,
|
||||
)
|
||||
)
|
||||
);
|
||||
} catch (StreamSocketClientException $e) {
|
||||
throw new Exception\RuntimeException(sprintf(
|
||||
'Unable to connect: %s: %d (%s)',
|
||||
$host,
|
||||
$e->getCode(),
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
if (!$this->socket) {
|
||||
throw new Exception\RuntimeException(sprintf(
|
||||
'Unable to connect: %s: %d (%s)',
|
||||
$host,
|
||||
$errno,
|
||||
$errstr
|
||||
));
|
||||
}
|
||||
stream_set_blocking($this->socket, 0);
|
||||
stream_set_write_buffer($this->socket, 0);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close Connection
|
||||
*
|
||||
* @return AbstractClient
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if ($this->isConnected && is_resource($this->socket)) {
|
||||
fclose($this->socket);
|
||||
}
|
||||
$this->isConnected = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Connected
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConnected()
|
||||
{
|
||||
return $this->isConnected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the Server
|
||||
*
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
protected function read($length = 6)
|
||||
{
|
||||
if (!$this->isConnected()) {
|
||||
throw new Exception\RuntimeException('You must open the connection prior to reading data');
|
||||
}
|
||||
$data = false;
|
||||
$read = array($this->socket);
|
||||
$null = null;
|
||||
|
||||
if (0 < @stream_select($read, $null, $null, 1, 0)) {
|
||||
$data = @fread($this->socket, (int) $length);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write Payload to the Server
|
||||
*
|
||||
* @param string $payload
|
||||
* @return int
|
||||
*/
|
||||
protected function write($payload)
|
||||
{
|
||||
if (!$this->isConnected()) {
|
||||
throw new Exception\RuntimeException('You must open the connection prior to writing data');
|
||||
}
|
||||
|
||||
return @fwrite($this->socket, $payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
}
|
48
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Client/Feedback.php
vendored
Normal file
48
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Client/Feedback.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @package Zend_Service
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Apns\Client;
|
||||
|
||||
use ZendService\Apple\Exception;
|
||||
use ZendService\Apple\Apns\Response\Feedback as FeedbackResponse;
|
||||
|
||||
/**
|
||||
* Feedback Client
|
||||
*/
|
||||
class Feedback extends AbstractClient
|
||||
{
|
||||
/**
|
||||
* APNS URIs
|
||||
* @var array
|
||||
*/
|
||||
protected $uris = array(
|
||||
'tls://feedback.sandbox.push.apple.com:2196',
|
||||
'tls://feedback.push.apple.com:2196'
|
||||
);
|
||||
|
||||
/**
|
||||
* Get Feedback
|
||||
*
|
||||
* @return array of ZendService\Apple\Apns\Response\Feedback
|
||||
*/
|
||||
public function feedback()
|
||||
{
|
||||
if (!$this->isConnected()) {
|
||||
throw new Exception\RuntimeException('You must first open the connection by calling open()');
|
||||
}
|
||||
|
||||
$tokens = array();
|
||||
while ($token = $this->read(38)) {
|
||||
$tokens[] = new FeedbackResponse($token);
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
}
|
56
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Client/Message.php
vendored
Normal file
56
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Client/Message.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @category ZendService
|
||||
* @package ZendService_Apple
|
||||
* @subpackage Apns
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Apns\Client;
|
||||
|
||||
use ZendService\Apple\Exception;
|
||||
use ZendService\Apple\Apns\Message as ApnsMessage;
|
||||
use ZendService\Apple\Apns\Response\Message as MessageResponse;
|
||||
|
||||
/**
|
||||
* Message Client
|
||||
*
|
||||
* @category ZendService
|
||||
* @package ZendService_Apple
|
||||
* @subpackage Apns
|
||||
*/
|
||||
class Message extends AbstractClient
|
||||
{
|
||||
/**
|
||||
* APNS URIs
|
||||
* @var array
|
||||
*/
|
||||
protected $uris = array(
|
||||
'tls://gateway.sandbox.push.apple.com:2195',
|
||||
'tls://gateway.push.apple.com:2195',
|
||||
);
|
||||
|
||||
/**
|
||||
* Send Message
|
||||
*
|
||||
* @param ApnsMessage $message
|
||||
* @return MessageResponse
|
||||
*/
|
||||
public function send(ApnsMessage $message)
|
||||
{
|
||||
if (!$this->isConnected()) {
|
||||
throw new Exception\RuntimeException('You must first open the connection by calling open()');
|
||||
}
|
||||
|
||||
$ret = $this->write($message->getPayloadJson());
|
||||
if ($ret === false) {
|
||||
throw new Exception\RuntimeException('Server is unavailable; please retry later');
|
||||
}
|
||||
|
||||
return new MessageResponse($this->read());
|
||||
}
|
||||
}
|
419
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Message.php
vendored
Normal file
419
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Message.php
vendored
Normal file
@@ -0,0 +1,419 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @package Zend_Service
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Apns;
|
||||
|
||||
use ZendService\Apple\Exception;
|
||||
use Zend\Json\Encoder as JsonEncoder;
|
||||
|
||||
/**
|
||||
* APNs Message
|
||||
*/
|
||||
class Message
|
||||
{
|
||||
/**
|
||||
* Identifier
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* APN Token
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* Expiration
|
||||
* @var int|null
|
||||
*/
|
||||
protected $expire;
|
||||
|
||||
/**
|
||||
* Alert Message
|
||||
* @var Message\Alert|null
|
||||
*/
|
||||
protected $alert;
|
||||
|
||||
/**
|
||||
* Badge
|
||||
* @var int|null
|
||||
*/
|
||||
protected $badge;
|
||||
|
||||
/**
|
||||
* Sound
|
||||
* @var string|null
|
||||
*/
|
||||
protected $sound;
|
||||
|
||||
/**
|
||||
* Content Available
|
||||
* @var int|null
|
||||
*/
|
||||
protected $contentAvailable;
|
||||
|
||||
/**
|
||||
* Category
|
||||
* @var string|null
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
/**
|
||||
* URL Arguments
|
||||
* @var array|null
|
||||
*/
|
||||
protected $urlArgs;
|
||||
|
||||
/**
|
||||
* Custom Attributes
|
||||
* @var array|null
|
||||
*/
|
||||
protected $custom;
|
||||
|
||||
/**
|
||||
* Get Identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Identifier
|
||||
*
|
||||
* @param string $id
|
||||
* @return Message
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
if (!is_scalar($id)) {
|
||||
throw new Exception\InvalidArgumentException('Identifier must be a scalar value');
|
||||
}
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Token
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Token
|
||||
*
|
||||
* @param string $token
|
||||
* @return Message
|
||||
*/
|
||||
public function setToken($token)
|
||||
{
|
||||
if (!is_string($token)) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Device token must be a string, "%s" given.',
|
||||
gettype($token)
|
||||
));
|
||||
}
|
||||
|
||||
if (preg_match('/[^0-9a-f]/', $token)) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Device token must be mask "%s". Token given: "%s"',
|
||||
'/[^0-9a-f]/',
|
||||
$token
|
||||
));
|
||||
}
|
||||
|
||||
if (strlen($token) != 64) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Device token must be a 64 charsets, Token length given: %d.',
|
||||
mb_strlen($token)
|
||||
));
|
||||
}
|
||||
|
||||
$this->token = $token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Expiration
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getExpire()
|
||||
{
|
||||
return $this->expire;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Expiration
|
||||
*
|
||||
* @param int|DateTime $expire
|
||||
* @return Message
|
||||
*/
|
||||
public function setExpire($expire)
|
||||
{
|
||||
if ($expire instanceof \DateTime) {
|
||||
$expire = $expire->getTimestamp();
|
||||
} elseif (!is_numeric($expire) || $expire != (int) $expire) {
|
||||
throw new Exception\InvalidArgumentException('Expiration must be a DateTime object or a unix timestamp');
|
||||
}
|
||||
$this->expire = $expire;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Alert
|
||||
*
|
||||
* @return Message\Alert|null
|
||||
*/
|
||||
public function getAlert()
|
||||
{
|
||||
return $this->alert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Alert
|
||||
*
|
||||
* @param string|Message\Alert|null $alert
|
||||
* @return Message
|
||||
*/
|
||||
public function setAlert($alert)
|
||||
{
|
||||
if (!$alert instanceof Message\Alert && !is_null($alert)) {
|
||||
$alert = new Message\Alert($alert);
|
||||
}
|
||||
$this->alert = $alert;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Badge
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getBadge()
|
||||
{
|
||||
return $this->badge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Badge
|
||||
*
|
||||
* @param int|null $badge
|
||||
* @return Message
|
||||
*/
|
||||
public function setBadge($badge)
|
||||
{
|
||||
if ($badge !== null && !$badge == (int) $badge) {
|
||||
throw new Exception\InvalidArgumentException('Badge must be null or an integer');
|
||||
}
|
||||
$this->badge = $badge;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Sound
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSound()
|
||||
{
|
||||
return $this->sound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Sound
|
||||
*
|
||||
* @param string|null $sound
|
||||
* @return Message
|
||||
*/
|
||||
public function setSound($sound)
|
||||
{
|
||||
if ($sound !== null && !is_string($sound)) {
|
||||
throw new Exception\InvalidArgumentException('Sound must be null or a string');
|
||||
}
|
||||
$this->sound = $sound;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content Available
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getContentAvailable()
|
||||
{
|
||||
return $this->contentAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content Available
|
||||
*
|
||||
* @param int|null $sound
|
||||
* @return Message
|
||||
*/
|
||||
public function setContentAvailable($value)
|
||||
{
|
||||
if ($value !== null && !is_int($value)) {
|
||||
throw new Exception\InvalidArgumentException('Content Available must be null or an integer');
|
||||
}
|
||||
$this->contentAvailable = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Category
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Category
|
||||
*
|
||||
* @param string|null $category
|
||||
* @return Message
|
||||
*/
|
||||
public function setCategory($category)
|
||||
{
|
||||
if ($category !== null && !is_string($category)) {
|
||||
throw new Exception\InvalidArgumentException('Category must be null or a string');
|
||||
}
|
||||
$this->category = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL arguments
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getUrlArgs()
|
||||
{
|
||||
return $this->urlArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set URL arguments
|
||||
*
|
||||
* @param array|null $urlArgs
|
||||
* @return Message
|
||||
*/
|
||||
public function setUrlArgs(array $urlArgs)
|
||||
{
|
||||
$this->urlArgs = $urlArgs;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Custom Data
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getCustom()
|
||||
{
|
||||
return $this->custom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Custom Data
|
||||
*
|
||||
* @param array $custom
|
||||
* @throws Exception\RuntimeException
|
||||
* @return Message
|
||||
*/
|
||||
public function setCustom(array $custom)
|
||||
{
|
||||
if (array_key_exists('aps', $custom)) {
|
||||
throw new Exception\RuntimeException('custom data must not contain aps key as it is reserved by apple');
|
||||
}
|
||||
|
||||
$this->custom = $custom;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Payload
|
||||
* Generate APN array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPayload()
|
||||
{
|
||||
$message = array();
|
||||
$aps = array();
|
||||
if ($this->alert && ($alert = $this->alert->getPayload())) {
|
||||
$aps['alert'] = $alert;
|
||||
}
|
||||
if (!is_null($this->badge)) {
|
||||
$aps['badge'] = $this->badge;
|
||||
}
|
||||
if (!is_null($this->sound)) {
|
||||
$aps['sound'] = $this->sound;
|
||||
}
|
||||
if (!is_null($this->contentAvailable)) {
|
||||
$aps['content-available'] = $this->contentAvailable;
|
||||
}
|
||||
if (!is_null($this->category)) {
|
||||
$aps['category'] = $this->category;
|
||||
}
|
||||
if (!is_null($this->urlArgs)) {
|
||||
$aps['url-args'] = $this->urlArgs;
|
||||
}
|
||||
if (!empty($this->custom)) {
|
||||
$message = array_merge($this->custom, $message);
|
||||
}
|
||||
if (!empty($aps)) {
|
||||
$message['aps'] = $aps;
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Payload JSON
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayloadJson()
|
||||
{
|
||||
$payload = $this->getPayload();
|
||||
// don't escape utf8 payloads unless json_encode does not exist.
|
||||
if (defined('JSON_UNESCAPED_UNICODE')) {
|
||||
$payload = json_encode($payload, JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$payload = JsonEncoder::encode($payload);
|
||||
}
|
||||
$length = strlen($payload);
|
||||
|
||||
return pack('CNNnH*', 1, $this->id, $this->expire, 32, $this->token)
|
||||
. pack('n', $length)
|
||||
. $payload;
|
||||
}
|
||||
}
|
345
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Message/Alert.php
vendored
Normal file
345
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Message/Alert.php
vendored
Normal file
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @package Zend_Service
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Apns\Message;
|
||||
|
||||
use ZendService\Apple\Exception;
|
||||
|
||||
/**
|
||||
* Message Alert Object
|
||||
*/
|
||||
class Alert
|
||||
{
|
||||
/**
|
||||
* Message Body
|
||||
* @var string|null
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Action Locale Key
|
||||
* @var string|null
|
||||
*/
|
||||
protected $actionLocKey;
|
||||
|
||||
/**
|
||||
* Locale Key
|
||||
* @var string|null
|
||||
*/
|
||||
protected $locKey;
|
||||
|
||||
/**
|
||||
* Locale Arguments
|
||||
* @var array|null
|
||||
*/
|
||||
protected $locArgs;
|
||||
|
||||
/**
|
||||
* Launch Image
|
||||
* @var string|null
|
||||
*/
|
||||
protected $launchImage;
|
||||
|
||||
/**
|
||||
* Message Title
|
||||
* @var string|null
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Title Locale Key
|
||||
* @var string|null
|
||||
*/
|
||||
protected $titleLocKey;
|
||||
|
||||
/**
|
||||
* Title Locale Arguments
|
||||
* @var array|null
|
||||
*/
|
||||
protected $titleLocArgs;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $body
|
||||
* @param string $actionLocKey
|
||||
* @param string $locKey
|
||||
* @param array $locArgs
|
||||
* @param string $launchImage
|
||||
* @return Alert
|
||||
*/
|
||||
public function __construct($body = null, $actionLocKey = null, $locKey = null, $locArgs = null, $launchImage = null, $title = null, $titleLocKey = null, $titleLocArgs = null)
|
||||
{
|
||||
if ($body !== null) {
|
||||
$this->setBody($body);
|
||||
}
|
||||
if ($actionLocKey !== null) {
|
||||
$this->setActionLocKey($actionLocKey);
|
||||
}
|
||||
if ($locKey !== null) {
|
||||
$this->setLocKey($locKey);
|
||||
}
|
||||
if ($locArgs !== null) {
|
||||
$this->setLocArgs($locArgs);
|
||||
}
|
||||
if ($launchImage !== null) {
|
||||
$this->setLaunchImage($launchImage);
|
||||
}
|
||||
if ($title !== null) {
|
||||
$this->setTitle($title);
|
||||
}
|
||||
if ($titleLocKey !== null) {
|
||||
$this->setTitleLocKey($titleLocKey);
|
||||
}
|
||||
if ($titleLocArgs !== null) {
|
||||
$this->setTitleLocArgs($titleLocArgs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Body
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Body
|
||||
*
|
||||
* @param string|null $body
|
||||
* @return Alert
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
if (!is_null($body) && !is_scalar($body)) {
|
||||
throw new Exception\InvalidArgumentException('Body must be null OR a scalar value');
|
||||
}
|
||||
$this->body = $body;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Action Locale Key
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getActionLocKey()
|
||||
{
|
||||
return $this->actionLocKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Action Locale Key
|
||||
*
|
||||
* @param string|null $key
|
||||
* @return Alert
|
||||
*/
|
||||
public function setActionLocKey($key)
|
||||
{
|
||||
if (!is_null($key) && !is_scalar($key)) {
|
||||
throw new Exception\InvalidArgumentException('ActionLocKey must be null OR a scalar value');
|
||||
}
|
||||
$this->actionLocKey = $key;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Locale Key
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLocKey()
|
||||
{
|
||||
return $this->locKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Locale Key
|
||||
*
|
||||
* @param string|null $key
|
||||
* @return Alert
|
||||
*/
|
||||
public function setLocKey($key)
|
||||
{
|
||||
if (!is_null($key) && !is_scalar($key)) {
|
||||
throw new Exception\InvalidArgumentException('LocKey must be null OR a scalar value');
|
||||
}
|
||||
$this->locKey = $key;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Locale Arguments
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getLocArgs()
|
||||
{
|
||||
return $this->locArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Locale Arguments
|
||||
*
|
||||
* @param array $args
|
||||
* @return Alert
|
||||
*/
|
||||
public function setLocArgs(array $args)
|
||||
{
|
||||
foreach ($args as $a) {
|
||||
if (!is_scalar($a)) {
|
||||
throw new Exception\InvalidArgumentException('Arguments must only contain scalar values');
|
||||
}
|
||||
}
|
||||
$this->locArgs = $args;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Launch Image
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLaunchImage()
|
||||
{
|
||||
return $this->launchImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Launch Image
|
||||
*
|
||||
* @param string|null $image
|
||||
* @return Alert
|
||||
*/
|
||||
public function setLaunchImage($image)
|
||||
{
|
||||
if (!is_null($image) && !is_scalar($image)) {
|
||||
throw new Exception\InvalidArgumentException('Launch image must be null OR a scalar value');
|
||||
}
|
||||
$this->launchImage = $image;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Title
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Title
|
||||
*
|
||||
* @param string|null $title
|
||||
* @return Alert
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
if (!is_null($title) && !is_scalar($title)) {
|
||||
throw new Exception\InvalidArgumentException('Title must be null OR a scalar value');
|
||||
}
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Title Locale Key
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTitleLocKey()
|
||||
{
|
||||
return $this->titleLocKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Title Locale Key
|
||||
*
|
||||
* @param string|null $key
|
||||
* @return Alert
|
||||
*/
|
||||
public function setTitleLocKey($key)
|
||||
{
|
||||
if (!is_null($key) && !is_scalar($key)) {
|
||||
throw new Exception\InvalidArgumentException('TitleLocKey must be null OR a scalar value');
|
||||
}
|
||||
$this->titleLocKey = $key;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Title Locale Arguments
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getTitleLocArgs()
|
||||
{
|
||||
return $this->titleLocArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Title Locale Arguments
|
||||
*
|
||||
* @param array $args
|
||||
* @return Alert
|
||||
*/
|
||||
public function setTitleLocArgs(array $args)
|
||||
{
|
||||
foreach ($args as $a) {
|
||||
if (!is_scalar($a)) {
|
||||
throw new Exception\InvalidArgumentException('Title Arguments must only contain scalar values');
|
||||
}
|
||||
}
|
||||
$this->titleLocArgs = $args;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* To Payload
|
||||
* Formats an APS alert.
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
public function getPayload()
|
||||
{
|
||||
$vars = get_object_vars($this);
|
||||
if (empty($vars)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$alert = array();
|
||||
foreach ($vars as $key => $value) {
|
||||
if (!is_null($value)) {
|
||||
$key = strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $key));
|
||||
$alert[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($alert) === 1) {
|
||||
return $this->getBody();
|
||||
}
|
||||
|
||||
return $alert;
|
||||
}
|
||||
}
|
107
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Response/Feedback.php
vendored
Normal file
107
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Response/Feedback.php
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @package Zend_Service
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Apns\Response;
|
||||
|
||||
use ZendService\Apple\Exception;
|
||||
|
||||
/**
|
||||
* Feedback Response
|
||||
*/
|
||||
class Feedback
|
||||
{
|
||||
/**
|
||||
* APNS Token
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* Time
|
||||
* @var int
|
||||
*/
|
||||
protected $time;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $rawResponse
|
||||
* @return Feedback
|
||||
*/
|
||||
public function __construct($rawResponse = null)
|
||||
{
|
||||
if ($rawResponse !== null) {
|
||||
$this->parseRawResponse($rawResponse);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Token
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Token
|
||||
*
|
||||
* @return Feedback
|
||||
*/
|
||||
public function setToken($token)
|
||||
{
|
||||
if (!is_scalar($token)) {
|
||||
throw new Exception\InvalidArgumentException('Token must be a scalar value');
|
||||
}
|
||||
$this->token = $token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Time
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTime()
|
||||
{
|
||||
return $this->time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Time
|
||||
*
|
||||
* @param int $time
|
||||
* @return Feedback
|
||||
*/
|
||||
public function setTime($time)
|
||||
{
|
||||
$this->time = (int) $time;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Raw Response
|
||||
*
|
||||
* @return Feedback
|
||||
*/
|
||||
public function parseRawResponse($rawResponse)
|
||||
{
|
||||
$rawResponse = trim($rawResponse);
|
||||
$token = unpack('Ntime/nlength/H*token', $rawResponse);
|
||||
$this->setTime($token['time']);
|
||||
$this->setToken(substr($token['token'], 0, $token['length'] * 2));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
141
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Response/Message.php
vendored
Normal file
141
vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Response/Message.php
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @category ZendService
|
||||
* @package ZendService_Apple
|
||||
* @subpackage Apns
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Apns\Response;
|
||||
|
||||
use ZendService\Apple\Exception;
|
||||
|
||||
/**
|
||||
* Message Response
|
||||
*
|
||||
* @category ZendService
|
||||
* @package ZendService_Apple
|
||||
* @subpackage Apns
|
||||
*/
|
||||
class Message
|
||||
{
|
||||
/**
|
||||
* Response Codes
|
||||
* @var int
|
||||
*/
|
||||
const RESULT_OK = 0;
|
||||
const RESULT_PROCESSING_ERROR = 1;
|
||||
const RESULT_MISSING_TOKEN = 2;
|
||||
const RESULT_MISSING_TOPIC = 3;
|
||||
const RESULT_MISSING_PAYLOAD = 4;
|
||||
const RESULT_INVALID_TOKEN_SIZE = 5;
|
||||
const RESULT_INVALID_TOPIC_SIZE = 6;
|
||||
const RESULT_INVALID_PAYLOAD_SIZE = 7;
|
||||
const RESULT_INVALID_TOKEN = 8;
|
||||
const RESULT_UNKNOWN_ERROR = 255;
|
||||
|
||||
/**
|
||||
* Identifier
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Result Code
|
||||
* @var int
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $rawResponse
|
||||
* @return Message
|
||||
*/
|
||||
public function __construct($rawResponse = null)
|
||||
{
|
||||
if ($rawResponse !== null) {
|
||||
$this->parseRawResponse($rawResponse);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Code
|
||||
*
|
||||
* @param int $code
|
||||
* @return Message
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
if (($code < 0 || $code > 8) && $code != 255) {
|
||||
throw new Exception\InvalidArgumentException('Code must be between 0-8 OR 255');
|
||||
}
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Identifier
|
||||
*
|
||||
* @param string $id
|
||||
* @return Message
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
if (!is_scalar($id)) {
|
||||
throw new Exception\InvalidArgumentException('Identifier must be a scalar value');
|
||||
}
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Raw Response
|
||||
*
|
||||
* @param string $rawResponse
|
||||
* @return Message
|
||||
*/
|
||||
public function parseRawResponse($rawResponse)
|
||||
{
|
||||
if (!is_scalar($rawResponse)) {
|
||||
throw new Exception\InvalidArgumentException('Response must be a scalar value');
|
||||
}
|
||||
|
||||
if (strlen($rawResponse) === 0) {
|
||||
$this->code = self::RESULT_OK;
|
||||
|
||||
return $this;
|
||||
}
|
||||
$response = unpack('Ccmd/Cerrno/Nid', $rawResponse);
|
||||
$this->setId($response['id']);
|
||||
$this->setCode($response['errno']);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @package Zend_Service
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Exception;
|
||||
|
||||
/**
|
||||
* Invalid Argument Exception
|
||||
*/
|
||||
class InvalidArgumentException extends \InvalidArgumentException
|
||||
{
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @package Zend_Service
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Exception;
|
||||
|
||||
class RuntimeException extends \RuntimeException
|
||||
{
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for creating stream_socket_client
|
||||
* @author Soshnikov Artem <213036@skobka.com>
|
||||
*/
|
||||
|
||||
namespace ZendService\Apple\Exception;
|
||||
|
||||
use ErrorException;
|
||||
|
||||
class StreamSocketClientException extends ErrorException
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user