Raw.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_Mpns **/
  22. require_once 'Zend/Mobile/Push/Message/Mpns.php';
  23. /** Zend_Xml_Security */
  24. require_once 'Zend/Xml/Security.php';
  25. /**
  26. * Mpns Raw 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. 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. * Message
  46. *
  47. * @var string
  48. */
  49. protected $_msg;
  50. /**
  51. * Get Delay
  52. *
  53. * @return int
  54. */
  55. public function getDelay()
  56. {
  57. if (!$this->_delay) {
  58. return self::DELAY_IMMEDIATE;
  59. }
  60. return $this->_delay;
  61. }
  62. /**
  63. * Set Delay
  64. *
  65. * @param int $delay
  66. * @return Zend_Mobile_Push_Message_Mpns_Raw
  67. * @throws Zend_Mobile_Push_Message_Exception
  68. */
  69. public function setDelay($delay)
  70. {
  71. if (!in_array($delay, array(
  72. self::DELAY_IMMEDIATE,
  73. self::DELAY_450S,
  74. self::DELAY_900S
  75. ))) {
  76. throw new Zend_Mobile_Push_Message_Exception('$delay must be one of the DELAY_* constants');
  77. }
  78. $this->_delay = $delay;
  79. return $this;
  80. }
  81. /**
  82. * Set Message
  83. *
  84. * @param string $msg XML string
  85. * @return Zend_Mobile_Push_Message_Mpns_Raw
  86. * @throws Zend_Mobile_Push_Message_Exception
  87. */
  88. public function setMessage($msg)
  89. {
  90. if (!is_string($msg)) {
  91. throw new Zend_Mobile_Push_Message_Exception('$msg is not a string');
  92. }
  93. if (!Zend_Xml_Security::scan($msg)) {
  94. throw new Zend_Mobile_Push_Message_Exception('$msg is not valid xml');
  95. }
  96. $this->_msg = $msg;
  97. return $this;
  98. }
  99. /**
  100. * Get Message
  101. *
  102. * @return string
  103. */
  104. public function getMessage()
  105. {
  106. return $this->_msg;
  107. }
  108. /**
  109. * Get Notification Type
  110. *
  111. * @return string
  112. */
  113. public static function getNotificationType()
  114. {
  115. return 'raw';
  116. }
  117. /**
  118. * Get XML Payload
  119. *
  120. * @return string
  121. */
  122. public function getXmlPayload()
  123. {
  124. return $this->_msg;
  125. }
  126. /**
  127. * Validate proper mpns message
  128. *
  129. * @return boolean
  130. */
  131. public function validate()
  132. {
  133. if (!isset($this->_token) || strlen($this->_token) === 0) {
  134. return false;
  135. }
  136. if (empty($this->_msg)) {
  137. return false;
  138. }
  139. return parent::validate();
  140. }
  141. }