apns-php
|
The Push Notification Provider. More...
Public Member Functions | |
void | add (ApnsPHP_Message $message) |
Adds a message to the message queue. More... | |
array | getErrors (boolean $bEmpty=true) |
Returns messages not delivered to the end user because one (or more) error occurred. More... | |
array | getQueue (boolean $bEmpty=true) |
Returns messages in the message queue. More... | |
integer | getSendRetryTimes () |
Get the send retry time value. More... | |
void | send () |
Sends all messages in the message queue to Apple Push Notification Service. More... | |
void | setSendRetryTimes (integer $nRetryTimes) |
Set the send retry times value. More... | |
Public Member Functions inherited from ApnsPHP_Abstract | |
void | __construct (integer $nEnvironment, string $sProviderCertificateFile) |
Constructor. More... | |
void | connect () |
Connects to Apple Push Notification service server. More... | |
boolean | disconnect () |
Disconnects from Apple Push Notifications service server. More... | |
string | getCertificateAuthority () |
Get the Root Certification Authority file path. More... | |
integer | getConnectRetryInterval () |
Get the connect retry interval. More... | |
integer | getConnectRetryTimes () |
Get the connect retry time value. More... | |
integer | getConnectTimeout () |
Get the connection timeout. More... | |
ApnsPHP_Log_Interface | getLogger () |
Get the Logger instance. More... | |
integer | getSocketSelectTimeout () |
Get the TCP socket select timeout. More... | |
integer | getWriteInterval () |
Get the write interval. More... | |
void | setConnectRetryInterval (integer $nRetryInterval) |
Set the connect retry interval. More... | |
void | setConnectRetryTimes (integer $nRetryTimes) |
Set the connect retry times value. More... | |
void | setConnectTimeout (integer $nTimeout) |
Set the connection timeout. More... | |
void | setLogger (ApnsPHP_Log_Interface $logger) |
Set the Logger instance to use for logging purpose. More... | |
void | setProviderCertificatePassphrase (string $sProviderCertificatePassphrase) |
Set the Provider Certificate passphrase. More... | |
void | setRootCertificationAuthority (string $sRootCertificationAuthorityFile) |
Set the Root Certification Authority file. More... | |
void | setSocketSelectTimeout (integer $nSelectTimeout) |
Set the TCP socket select timeout. More... | |
void | setWriteInterval (integer $nWriteInterval) |
Set the write interval. More... | |
Data Fields | |
const | COMMAND_PUSH = 1 |
integer Payload command. More... | |
const | ERROR_RESPONSE_COMMAND = 8 |
integer Error-response command code. More... | |
const | ERROR_RESPONSE_SIZE = 6 |
integer Error-response packet size. More... | |
const | STATUS_CODE_INTERNAL_ERROR = 999 |
integer Status code for internal error (not Apple). More... | |
Data Fields inherited from ApnsPHP_Abstract | |
const | CONNECT_RETRY_INTERVAL = 1000000 |
integer Default connect retry interval in micro seconds. More... | |
const | DEVICE_BINARY_SIZE = 32 |
integer Device token length. More... | |
const | ENVIRONMENT_PRODUCTION = 0 |
integer Production environment. More... | |
const | ENVIRONMENT_SANDBOX = 1 |
integer Sandbox environment. More... | |
const | SOCKET_SELECT_TIMEOUT = 1000000 |
integer Default socket select timeout in micro seconds. More... | |
const | WRITE_INTERVAL = 10000 |
integer Default write interval in micro seconds. More... | |
Protected Member Functions | |
string | _getBinaryNotification (string $sDeviceToken, string $sPayload, integer $nMessageID=0, integer $nExpire=604800) |
Generate a binary notification from a device token and a JSON-encoded payload. More... | |
array | _parseErrorMessage (string $sErrorMessage) |
Parses the error message. More... | |
array null | _readErrorMessage () |
Reads an error message (if present) from the main stream. More... | |
void | _removeMessageFromQueue (integer $nMessageID, boolean $bError=false) |
Remove a message from the message queue. More... | |
boolean | _updateQueue (array $aErrorMessage=null) |
Checks for error message and deletes messages successfully sent from message queue. More... | |
Protected Member Functions inherited from ApnsPHP_Abstract | |
boolean | _connect () |
Connects to Apple Push Notification service server. More... | |
void | _log (string $sMessage) |
Logs a message through the Logger. More... | |
Protected Attributes | |
$_aErrorResponseMessages | |
array Error-response messages. More... | |
array | $_aErrors = array() |
Error container. More... | |
array | $_aMessageQueue = array() |
Message queue. More... | |
$_aServiceURLs | |
array Service URLs environments. More... | |
integer | $_nSendRetryTimes = 3 |
Send retry times. More... | |
Protected Attributes inherited from ApnsPHP_Abstract | |
array | $_aServiceURLs = array() |
Container for service URLs environments. More... | |
resource | $_hSocket |
SSL Socket. More... | |
ApnsPHP_Log_Interface | $_logger |
Logger. More... | |
integer | $_nConnectRetryInterval |
Connect retry interval in micro seconds. More... | |
integer | $_nConnectRetryTimes = 3 |
Connect retry times. More... | |
integer | $_nConnectTimeout |
Connect timeout in seconds. More... | |
integer | $_nEnvironment |
Active environment. More... | |
integer | $_nSocketSelectTimeout |
Socket select timeout in micro seconds. More... | |
integer | $_nWriteInterval |
Write interval in micro seconds. More... | |
string | $_sProviderCertificateFile |
Provider certificate file with key (Bundled PEM). More... | |
string | $_sProviderCertificatePassphrase |
Provider certificate passphrase. More... | |
string | $_sRootCertificationAuthorityFile |
Root certification authority file. More... | |
The Push Notification Provider.
The class manages a message queue and sends notifications payload to Apple Push Notification Service.
|
protected |
Generate a binary notification from a device token and a JSON-encoded payload.
$sDeviceToken | The device token. |
$sPayload | The JSON-encoded payload. |
$nMessageID | [optional] Message unique ID. |
$nExpire | [optional] Seconds, starting from now, that identifies when the notification is no longer valid and can be discarded. Pass a negative value (-1 for example) to request that APNs not store the notification at all. Default is 86400 * 7, 7 days. |
Definition at line 263 of file Push.php.
Referenced by add().
|
protected |
Parses the error message.
$sErrorMessage | The Error Message. |
Definition at line 281 of file Push.php.
Referenced by _readErrorMessage().
|
protected |
Reads an error message (if present) from the main stream.
If the error message is present and valid the error message is returned, otherwhise null is returned.
Definition at line 293 of file Push.php.
References _parseErrorMessage().
Referenced by _updateQueue().
|
protected |
Remove a message from the message queue.
$nMessageID | The Message ID. |
$bError | [optional] Insert the message in the Error container. |
ApnsPHP_Push_Exception | if the Message ID is not valid or message does not exists. |
Definition at line 371 of file Push.php.
Referenced by send().
|
protected |
Checks for error message and deletes messages successfully sent from message queue.
$aErrorMessage | [optional] The error message. It will anyway always be read from the main stream. The latest successful message sent is the lowest between this error message and the message that was read from the main stream. |
Definition at line 327 of file Push.php.
References ApnsPHP_Abstract::_log(), _readErrorMessage(), ApnsPHP_Abstract::connect(), and ApnsPHP_Abstract::disconnect().
Referenced by send().
void add | ( | ApnsPHP_Message | $message | ) |
Adds a message to the message queue.
$message | The message. |
Definition at line 93 of file Push.php.
References _getBinaryNotification(), ApnsPHP_Message::getExpiry(), ApnsPHP_Message::getPayload(), ApnsPHP_Message::getRecipient(), and ApnsPHP_Message::getRecipientsNumber().
array getErrors | ( | boolean | $bEmpty = true | ) |
array getQueue | ( | boolean | $bEmpty = true | ) |
Returns messages in the message queue.
When a message is successful sent or reached the maximum retry time is removed from the message queue and inserted in the Errors container. Use the getErrors() method to retrive messages with delivery error(s).
$bEmpty | [optional] Empty message queue. |
Definition at line 223 of file Push.php.
References $_aMessageQueue.
integer getSendRetryTimes | ( | ) |
Get the send retry time value.
Definition at line 83 of file Push.php.
References $_nSendRetryTimes.
void send | ( | ) |
Sends all messages in the message queue to Apple Push Notification Service.
ApnsPHP_Push_Exception | if not connected to the service or no notification queued. |
Definition at line 120 of file Push.php.
References ApnsPHP_Abstract::_log(), _removeMessageFromQueue(), and _updateQueue().
void setSendRetryTimes | ( | integer | $nRetryTimes | ) |
|
protected |
array Error-response messages.
|
protected |
|
protected |
|
protected |
|
protected |
const ERROR_RESPONSE_COMMAND = 8 |
const ERROR_RESPONSE_SIZE = 6 |
const STATUS_CODE_INTERNAL_ERROR = 999 |