Raw.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. /** Zend_Mobile_Push_Message_Mpns **/
  22. require_once 'Zend/Mobile/Push/Message/Mpns.php';
  23. /**
  24. * Mpns Raw Message
  25. *
  26. * @category Zend
  27. * @package Zend_Mobile
  28. * @subpackage Zend_Mobile_Push
  29. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Mobile_Push_Message_Mpns_Raw extends Zend_Mobile_Push_Message_Mpns
  33. {
  34. /**
  35. * Mpns delays
  36. *
  37. * @var int
  38. */
  39. const DELAY_IMMEDIATE = 3;
  40. const DELAY_450S = 13;
  41. const DELAY_900S = 23;
  42. /**
  43. * Message
  44. *
  45. * @var string
  46. */
  47. protected $_msg;
  48. /**
  49. * Get Delay
  50. *
  51. * @return int
  52. */
  53. public function getDelay()
  54. {
  55. if (!$this->_delay) {
  56. return self::DELAY_IMMEDIATE;
  57. }
  58. return $this->_delay;
  59. }
  60. /**
  61. * Set Delay
  62. *
  63. * @param int $delay
  64. * @return Zend_Mobile_Push_Message_Mpns_Raw
  65. * @throws Zend_Mobile_Push_Message_Exception
  66. */
  67. public function setDelay($delay)
  68. {
  69. if (!in_array($delay, array(
  70. self::DELAY_IMMEDIATE,
  71. self::DELAY_450S,
  72. self::DELAY_900S
  73. ))) {
  74. throw new Zend_Mobile_Push_Message_Exception('$delay must be one of the DELAY_* constants');
  75. }
  76. $this->_delay = $delay;
  77. return $this;
  78. }
  79. /**
  80. * Set Message
  81. *
  82. * @param string $msg XML string
  83. * @return Zend_Mobile_Push_Message_Mpns_Raw
  84. * @throws Zend_Mobile_Push_Message_Exception
  85. */
  86. public function setMessage($msg)
  87. {
  88. if (!is_string($msg)) {
  89. throw new Zend_Mobile_Push_Message_Exception('$msg is not a string');
  90. }
  91. if (!simplexml_load_string($msg)) {
  92. throw new Zend_Mobile_Push_Message_Exception('$msg is not valid xml');
  93. }
  94. $this->_msg = $msg;
  95. return $this;
  96. }
  97. /**
  98. * Get Message
  99. *
  100. * @return string
  101. */
  102. public function getMessage()
  103. {
  104. return $this->_msg;
  105. }
  106. /**
  107. * Get Notification Type
  108. *
  109. * @return string
  110. */
  111. public static function getNotificationType()
  112. {
  113. return 'raw';
  114. }
  115. /**
  116. * Get XML Payload
  117. *
  118. * @return string
  119. */
  120. public function getXmlPayload()
  121. {
  122. return $this->_msg;
  123. }
  124. /**
  125. * Validate proper mpns message
  126. *
  127. * @return boolean
  128. */
  129. public function validate()
  130. {
  131. if (!isset($this->_token) || strlen($this->_token) === 0) {
  132. return false;
  133. }
  134. if (empty($this->_msg)) {
  135. return false;
  136. }
  137. return parent::validate();
  138. }
  139. }