Mpns.php 2.7 KB

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