File indexing completed on 2025-03-02 05:29:35
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Mobile 0017 * @subpackage Zend_Mobile_Push 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 */ 0021 0022 /** Zend_Mobile_Push_Message_Mpns **/ 0023 // require_once 'Zend/Mobile/Push/Message/Mpns.php'; 0024 0025 /** Zend_Xml_Security */ 0026 // require_once 'Zend/Xml/Security.php'; 0027 0028 /** 0029 * Mpns Raw Message 0030 * 0031 * @category Zend 0032 * @package Zend_Mobile 0033 * @subpackage Zend_Mobile_Push 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 */ 0037 class Zend_Mobile_Push_Message_Mpns_Raw extends Zend_Mobile_Push_Message_Mpns 0038 { 0039 /** 0040 * Mpns delays 0041 * 0042 * @var int 0043 */ 0044 const DELAY_IMMEDIATE = 3; 0045 const DELAY_450S = 13; 0046 const DELAY_900S = 23; 0047 0048 /** 0049 * Message 0050 * 0051 * @var string 0052 */ 0053 protected $_msg; 0054 0055 /** 0056 * Get Delay 0057 * 0058 * @return int 0059 */ 0060 public function getDelay() 0061 { 0062 if (!$this->_delay) { 0063 return self::DELAY_IMMEDIATE; 0064 } 0065 return $this->_delay; 0066 } 0067 0068 /** 0069 * Set Delay 0070 * 0071 * @param int $delay 0072 * @return Zend_Mobile_Push_Message_Mpns_Raw 0073 * @throws Zend_Mobile_Push_Message_Exception 0074 */ 0075 public function setDelay($delay) 0076 { 0077 if (!in_array($delay, array( 0078 self::DELAY_IMMEDIATE, 0079 self::DELAY_450S, 0080 self::DELAY_900S 0081 ))) { 0082 throw new Zend_Mobile_Push_Message_Exception('$delay must be one of the DELAY_* constants'); 0083 } 0084 $this->_delay = $delay; 0085 return $this; 0086 } 0087 0088 /** 0089 * Set Message 0090 * 0091 * @param string $msg XML string 0092 * @return Zend_Mobile_Push_Message_Mpns_Raw 0093 * @throws Zend_Mobile_Push_Message_Exception 0094 */ 0095 public function setMessage($msg) 0096 { 0097 if (!is_string($msg)) { 0098 throw new Zend_Mobile_Push_Message_Exception('$msg is not a string'); 0099 } 0100 if (!Zend_Xml_Security::scan($msg)) { 0101 throw new Zend_Mobile_Push_Message_Exception('$msg is not valid xml'); 0102 } 0103 $this->_msg = $msg; 0104 return $this; 0105 } 0106 0107 /** 0108 * Get Message 0109 * 0110 * @return string 0111 */ 0112 public function getMessage() 0113 { 0114 return $this->_msg; 0115 } 0116 0117 /** 0118 * Get Notification Type 0119 * 0120 * @return string 0121 */ 0122 public static function getNotificationType() 0123 { 0124 return 'raw'; 0125 } 0126 0127 /** 0128 * Get XML Payload 0129 * 0130 * @return string 0131 */ 0132 public function getXmlPayload() 0133 { 0134 return $this->_msg; 0135 } 0136 0137 /** 0138 * Validate proper mpns message 0139 * 0140 * @return boolean 0141 */ 0142 public function validate() 0143 { 0144 if (!isset($this->_token) || strlen($this->_token) === 0) { 0145 return false; 0146 } 0147 if (empty($this->_msg)) { 0148 return false; 0149 } 0150 return parent::validate(); 0151 } 0152 }