web/lib/Zend/Mobile/Push/Message/Mpns.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_Abstract **/
       
    23 require_once 'Zend/Mobile/Push/Message/Abstract.php';
       
    24 
       
    25 /** Zend_Uri **/
       
    26 require_once 'Zend/Uri.php';
       
    27 
       
    28 /**
       
    29  * Mpns Message
       
    30  *
       
    31  * @category   Zend
       
    32  * @package    Zend_Mobile
       
    33  * @subpackage Zend_Mobile_Push
       
    34  * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
       
    35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    36  */
       
    37 abstract class Zend_Mobile_Push_Message_Mpns extends Zend_Mobile_Push_Message_Abstract
       
    38 {
       
    39     /**
       
    40      * Mpns types
       
    41      *
       
    42      * @var string
       
    43      */
       
    44     const TYPE_RAW = 'raw';
       
    45     const TYPE_TILE = 'token';
       
    46     const TYPE_TOAST = 'toast';
       
    47 
       
    48     /**
       
    49      * Delay
       
    50      *
       
    51      * @var int
       
    52      */
       
    53     protected $_delay;
       
    54 
       
    55     /**
       
    56      * Get Delay
       
    57      *
       
    58      * @return int
       
    59      */
       
    60     abstract public function getDelay();
       
    61 
       
    62     /**
       
    63      * Set Delay
       
    64      *
       
    65      * @param int $delay one of const DELAY_* of implementing classes
       
    66      * @return Zend_Mobile_Push_Message_Mpns
       
    67      */
       
    68     abstract public function setDelay($delay);
       
    69 
       
    70     /**
       
    71      * Get Notification Type
       
    72      *
       
    73      * @return string
       
    74      */
       
    75     public static function getNotificationType()
       
    76     {
       
    77         return "";
       
    78     }
       
    79 
       
    80     /**
       
    81      * Set Token
       
    82      *
       
    83      * @param string $token
       
    84      * @return Zend_Mobile_Push_Message_Mpns
       
    85      * @throws Zend_Mobile_Push_Message_Exception
       
    86      */
       
    87     public function setToken($token)
       
    88     {
       
    89         if (!is_string($token)) {
       
    90             throw new Zend_Mobile_Push_Message_Exception('$token is not a string');
       
    91         }
       
    92         if (!Zend_Uri::check($token)) {
       
    93             throw new Zend_Mobile_Push_Message_Exception('$token is not a valid URI');
       
    94         }
       
    95         return parent::setToken($token);
       
    96     }
       
    97 
       
    98     /**
       
    99      * Get XML Payload
       
   100      *
       
   101      * @return string
       
   102      */
       
   103     abstract public function getXmlPayload();
       
   104 
       
   105     /**
       
   106      * Validate proper mpns message
       
   107      *
       
   108      * @return boolean
       
   109      */
       
   110     public function validate()
       
   111     {
       
   112         if (!isset($this->_token) || strlen($this->_token) === 0) {
       
   113             return false;
       
   114         }
       
   115         return parent::validate();
       
   116     }
       
   117 }