VoiceButlerAbstract.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_VoiceButler_VoiceButlerAbstract
  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. * returns the return object
  45. *
  46. * @return stdClass
  47. */
  48. public function getReturn()
  49. {
  50. return $this->return;
  51. }
  52. /**
  53. * parse the response data and throws exceptions
  54. *
  55. * @throws Zend_Service_DeveloperGarden_Response_Exception
  56. * @return Zend_Service_DeveloperGarden_Response_ResponseAbstract
  57. */
  58. public function parse()
  59. {
  60. if ($this->hasError()) {
  61. throw new Zend_Service_DeveloperGarden_Response_Exception(
  62. $this->getErrorMessage(),
  63. $this->getErrorCode()
  64. );
  65. }
  66. return $this;
  67. }
  68. /**
  69. * returns the error code
  70. *
  71. * @return string|null
  72. */
  73. public function getErrorCode()
  74. {
  75. $retValue = null;
  76. if ($this->return instanceof stdClass) {
  77. $retValue = $this->return->status;
  78. }
  79. return $retValue;
  80. }
  81. /**
  82. * returns the error message
  83. *
  84. * @return string
  85. */
  86. public function getErrorMessage()
  87. {
  88. $retValue = null;
  89. if ($this->return instanceof stdClass) {
  90. $retValue = $this->return->err_msg;
  91. }
  92. return $retValue;
  93. }
  94. /**
  95. * returns true if the errorCode is not null and not 0000
  96. *
  97. * @return boolean
  98. */
  99. public function isValid()
  100. {
  101. return ($this->return === null
  102. || $this->return->status == '0000');
  103. }
  104. /**
  105. * returns true if we have a error situation
  106. *
  107. * @return boolean
  108. */
  109. public function hasError()
  110. {
  111. $retValue = false;
  112. if ($this->return instanceof stdClass
  113. && $this->return->status != '0000'
  114. ) {
  115. $retValue = true;
  116. }
  117. return $retValue;
  118. }
  119. }