ResponseAbstract.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_Exception
  24. */
  25. require_once 'Zend/Service/DeveloperGarden/Response/Exception.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_ResponseAbstract
  35. {
  36. /**
  37. * errorCode
  38. *
  39. * @var string
  40. */
  41. public $errorCode = null;
  42. /**
  43. * errorMessage
  44. *
  45. * @var string
  46. */
  47. public $errorMessage = null;
  48. /**
  49. * parse the token data and throws exceptions
  50. *
  51. * @throws Zend_Service_DeveloperGarden_Response_Exception
  52. * @return Zend_Service_DeveloperGarden_Response_ResponseAbstract
  53. */
  54. public function parse()
  55. {
  56. if ($this->hasError()) {
  57. throw new Zend_Service_DeveloperGarden_Response_Exception(
  58. $this->getErrorMessage(),
  59. $this->getErrorCode()
  60. );
  61. }
  62. return $this;
  63. }
  64. /**
  65. * returns the error code
  66. *
  67. * @return string|null
  68. */
  69. public function getErrorCode()
  70. {
  71. return $this->errorCode;
  72. }
  73. /**
  74. * returns the error message
  75. *
  76. * @return string
  77. */
  78. public function getErrorMessage()
  79. {
  80. return $this->errorMessage;
  81. }
  82. /**
  83. * returns true if the errorCode is not null and not 0000
  84. *
  85. * @return boolean
  86. */
  87. public function isValid()
  88. {
  89. return ($this->errorCode === null
  90. || $this->errorCode == '0000');
  91. }
  92. /**
  93. * returns true if we have a error situation
  94. *
  95. * @return boolean
  96. */
  97. public function hasError()
  98. {
  99. return ($this->errorCode !== null
  100. && $this->errorCode != '0000');
  101. }
  102. }