web/lib/Zend/Mobile/Push/Message/Gcm.php
changeset 1230 68c69c656a2c
parent 808 6b6c2214f778
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Mobile
    16  * @package    Zend_Mobile
    17  * @subpackage Zend_Mobile_Push
    17  * @subpackage Zend_Mobile_Push
    18  * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id$
    20  * @version    $Id$
    21  */
    21  */
    22 
    22 
    23 /** Zend_Mobile_Push_Message_Abstract **/
    23 /** Zend_Mobile_Push_Message_Abstract **/
    27  * Gcm Message
    27  * Gcm Message
    28  *
    28  *
    29  * @category   Zend
    29  * @category   Zend
    30  * @package    Zend_Mobile
    30  * @package    Zend_Mobile
    31  * @subpackage Zend_Mobile_Push
    31  * @subpackage Zend_Mobile_Push
    32  * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
    32  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  * @version    $Id$
    34  * @version    $Id$
    35  * @method     array getToken()
    35  * @method     array getToken()
    36  */
    36  */
    37 class Zend_Mobile_Push_Message_Gcm extends Zend_Mobile_Push_Message_Abstract
    37 class Zend_Mobile_Push_Message_Gcm extends Zend_Mobile_Push_Message_Abstract
    61     /**
    61     /**
    62      * Time to live in seconds
    62      * Time to live in seconds
    63      * 
    63      * 
    64      * @var int
    64      * @var int
    65      */
    65      */
    66     protected $_ttl = 0;
    66     protected $_ttl = 2419200;
    67 
    67 
    68     /**
    68     /**
    69      * Add a Token
    69      * Add a Token
    70      *
    70      *
    71      * @param  string $token
    71      * @param  string $token
   197     {
   197     {
   198         return $this->_delay;
   198         return $this->_delay;
   199     }
   199     }
   200 
   200 
   201     /**
   201     /**
   202      * Set time to live
   202      * Set time to live.
   203      * If $secs is set to 0 it will be handled as
       
   204      * not being set.
       
   205      *
   203      *
   206      * @param  int $secs
   204      * @param  int $secs
       
   205      * @throws Zend_Mobile_Push_Message_Exception
   207      * @return Zend_Mobile_Push_Message_Gcm
   206      * @return Zend_Mobile_Push_Message_Gcm
   208      */
   207      */
   209     public function setTtl($secs)
   208     public function setTtl($secs)
   210     {
   209     {
   211         if (!is_numeric($secs)) {
   210         if (!is_numeric($secs)) {
   234     public function validate()
   233     public function validate()
   235     {
   234     {
   236         if (!is_array($this->_token) || empty($this->_token)) {
   235         if (!is_array($this->_token) || empty($this->_token)) {
   237             return false;
   236             return false;
   238         }
   237         }
   239         if ($this->_ttl > 0 &&
   238         if ($this->_ttl !== 2419200 &&
   240             (!is_scalar($this->_id) ||
   239             (!is_scalar($this->_id) ||
   241             strlen($this->_id) === 0)) {
   240             strlen($this->_id) === 0)) {
   242             return false;
   241             return false;
   243         }
   242         }
   244         return true;
   243         return true;
   264             $json['data'] = $this->_data;
   263             $json['data'] = $this->_data;
   265         }
   264         }
   266         if ($this->_delay) {
   265         if ($this->_delay) {
   267             $json['delay_while_idle'] = $this->_delay;
   266             $json['delay_while_idle'] = $this->_delay;
   268         }
   267         }
   269         if ($this->_ttl) {
   268         if ($this->_ttl !== 2419200) {
   270             $json['time_to_live'] = $this->_ttl;
   269             $json['time_to_live'] = $this->_ttl;
   271         }
   270         }
   272         return json_encode($json);
   271         if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
       
   272             return json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
       
   273         } else {
       
   274             return json_encode($json);
       
   275         }
   273     }
   276     }
   274 }
   277 }