web/lib/Zend/Mobile/Push/Message/Mpns/Raw.php
changeset 808 6b6c2214f778
child 1230 68c69c656a2c
equal deleted inserted replaced
807:877f952ae2bd 808:6b6c2214f778
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Mobile
       
    17  * @subpackage Zend_Mobile_Push
       
    18  * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  */
       
    21 
       
    22 /** Zend_Mobile_Push_Message_Mpns **/
       
    23 require_once 'Zend/Mobile/Push/Message/Mpns.php';
       
    24 
       
    25 /**
       
    26  * Mpns Raw Message
       
    27  *
       
    28  * @category   Zend
       
    29  * @package    Zend_Mobile
       
    30  * @subpackage Zend_Mobile_Push
       
    31  * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
       
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    33  */
       
    34 class Zend_Mobile_Push_Message_Mpns_Raw extends Zend_Mobile_Push_Message_Mpns
       
    35 {
       
    36     /**
       
    37      * Mpns delays
       
    38      *
       
    39      * @var int
       
    40      */
       
    41     const DELAY_IMMEDIATE = 3;
       
    42     const DELAY_450S = 13;
       
    43     const DELAY_900S = 23;
       
    44 
       
    45     /**
       
    46      * Message
       
    47      *
       
    48      * @var string
       
    49      */
       
    50     protected $_msg;
       
    51 
       
    52     /**
       
    53      * Get Delay
       
    54      *
       
    55      * @return int
       
    56      */
       
    57     public function getDelay()
       
    58     {
       
    59         if (!$this->_delay) {
       
    60             return self::DELAY_IMMEDIATE;
       
    61         }
       
    62         return $this->_delay;
       
    63     }
       
    64 
       
    65     /**
       
    66      * Set Delay
       
    67      *
       
    68      * @param int $delay
       
    69      * @return Zend_Mobile_Push_Message_Mpns_Raw
       
    70      * @throws Zend_Mobile_Push_Message_Exception
       
    71      */
       
    72     public function setDelay($delay)
       
    73     {
       
    74         if (!in_array($delay, array(
       
    75             self::DELAY_IMMEDIATE,
       
    76             self::DELAY_450S,
       
    77             self::DELAY_900S
       
    78         ))) {
       
    79             throw new Zend_Mobile_Push_Message_Exception('$delay must be one of the DELAY_* constants');
       
    80         }
       
    81         $this->_delay = $delay;
       
    82         return $this;
       
    83     }
       
    84 
       
    85     /**
       
    86      * Set Message
       
    87      *
       
    88      * @param string $msg XML string
       
    89      * @return Zend_Mobile_Push_Message_Mpns_Raw
       
    90      * @throws Zend_Mobile_Push_Message_Exception
       
    91      */
       
    92     public function setMessage($msg)
       
    93     {
       
    94         if (!is_string($msg)) {
       
    95             throw new Zend_Mobile_Push_Message_Exception('$msg is not a string');
       
    96         }
       
    97         if (!simplexml_load_string($msg)) {
       
    98             throw new Zend_Mobile_Push_Message_Exception('$msg is not valid xml');
       
    99         }
       
   100         $this->_msg = $msg;
       
   101         return $this;
       
   102     }
       
   103 
       
   104     /**
       
   105      * Get Message
       
   106      *
       
   107      * @return string
       
   108      */
       
   109     public function getMessage()
       
   110     {
       
   111         return $this->_msg;
       
   112     }
       
   113 
       
   114     /**
       
   115      * Get Notification Type
       
   116      *
       
   117      * @return string
       
   118      */
       
   119     public static function getNotificationType()
       
   120     {
       
   121         return 'raw';
       
   122     }
       
   123 
       
   124     /**
       
   125      * Get XML Payload
       
   126      *
       
   127      * @return string
       
   128      */
       
   129     public function getXmlPayload()
       
   130     {
       
   131         return $this->_msg;
       
   132     }
       
   133 
       
   134     /**
       
   135      * Validate proper mpns message
       
   136      *
       
   137      * @return boolean
       
   138      */
       
   139     public function validate()
       
   140     {
       
   141         if (!isset($this->_token) || strlen($this->_token) === 0) {
       
   142             return false;
       
   143         }
       
   144         if (empty($this->_msg)) {
       
   145             return false;
       
   146         }
       
   147         return parent::validate();
       
   148     }
       
   149 }