BaseExceptionResponse.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace NavOnlineInvoice;
  3. use Exception;
  4. abstract class BaseExceptionResponse extends Exception {
  5. protected $xml;
  6. function __construct($xml) {
  7. $this->xml = $xml;
  8. $message = $this->getResultMessage();
  9. parent::__construct($message);
  10. }
  11. public function getXml() {
  12. return $this->xml;
  13. }
  14. /**
  15. * Return the result field of the XML in array format
  16. * @return array
  17. */
  18. abstract public function getResult();
  19. public function getResultMessage() {
  20. $result = $this->getResult();
  21. if (empty($result["message"])) {
  22. $message = $result["errorCode"];
  23. } elseif (empty($result["errorCode"])) {
  24. $message = $result["message"];
  25. } else {
  26. $message = "$result[message] ($result[errorCode])";
  27. }
  28. return $message;
  29. }
  30. public function getErrorCode() {
  31. $result = $this->getResult();
  32. if (isset($result["errorCode"])) {
  33. return (string)$result["errorCode"];
  34. }
  35. return null;
  36. }
  37. }