SendSmsAbstract.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_Service
  17. * @subpackage DeveloperGarden
  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
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Service_DeveloperGarden_Response_ResponseAbstract
  24. */
  25. require_once 'Zend/Service/DeveloperGarden/Response/ResponseAbstract.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Service
  29. * @subpackage DeveloperGarden
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @author Marco Kaiser
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. abstract class Zend_Service_DeveloperGarden_Response_SendSms_SendSmsAbstract
  35. extends Zend_Service_DeveloperGarden_Response_ResponseAbstract
  36. {
  37. /**
  38. * the return from the sms request
  39. *
  40. * @var stdClass
  41. */
  42. public $return = null;
  43. /**
  44. * parse the response data and throws exceptions
  45. *
  46. * @throws Zend_Service_DeveloperGarden_Response_Exception
  47. * @return Zend_Service_DeveloperGarden_Response_ResponseAbstract
  48. */
  49. public function parse()
  50. {
  51. if ($this->hasError()) {
  52. require_once 'Zend/Service/DeveloperGarden/Response/Exception.php';
  53. throw new Zend_Service_DeveloperGarden_Response_Exception(
  54. $this->getErrorMessage(),
  55. $this->getErrorCode()
  56. );
  57. }
  58. return $this;
  59. }
  60. /**
  61. * returns the error code
  62. *
  63. * @return string|null
  64. */
  65. public function getErrorCode()
  66. {
  67. $retValue = null;
  68. if ($this->return instanceof stdClass) {
  69. $retValue = $this->return->status;
  70. }
  71. return $retValue;
  72. }
  73. /**
  74. * returns the error message
  75. *
  76. * @return string
  77. */
  78. public function getErrorMessage()
  79. {
  80. $retValue = null;
  81. if ($this->return instanceof stdClass) {
  82. $retValue = $this->return->description;
  83. }
  84. return $retValue;
  85. }
  86. /**
  87. * returns true if the errorCode is not null and not 0000
  88. *
  89. * @return boolean
  90. */
  91. public function isValid()
  92. {
  93. return ($this->return === null
  94. || $this->return->status == '0000');
  95. }
  96. /**
  97. * returns true if we have a error situation
  98. *
  99. * @return boolean
  100. */
  101. public function hasError()
  102. {
  103. $retValue = false;
  104. if ($this->return instanceof stdClass
  105. && $this->return->status != '0000'
  106. ) {
  107. $retValue = true;
  108. }
  109. return $retValue;
  110. }
  111. }