Error.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Akeeba Engine
  4. *
  5. * @package akeebaengine
  6. * @copyright Copyright (c)2006-2020 Nicholas K. Dionysopoulos / Akeeba Ltd
  7. * @license GNU General Public License version 3, or later
  8. */
  9. namespace Akeeba\Engine\Postproc\Connector\S3v4\Response;
  10. // Protection against direct access
  11. defined('AKEEBAENGINE') or die();
  12. /**
  13. * S3 response error object
  14. */
  15. class Error
  16. {
  17. /**
  18. * Error code
  19. *
  20. * @var int
  21. */
  22. private $code = 0;
  23. /**
  24. * Error message
  25. *
  26. * @var string
  27. */
  28. private $message = '';
  29. /**
  30. * URI to the resource that throws the error
  31. *
  32. * @var string
  33. */
  34. private $resource = '';
  35. /**
  36. * Create a new error object
  37. *
  38. * @param int $code The error code
  39. * @param string $message The error message
  40. * @param string $resource The URI to the resource throwing the error
  41. *
  42. * @return Error
  43. */
  44. function __construct($code = 0, $message = '', $resource = '')
  45. {
  46. $this->setCode($code);
  47. $this->setMessage($message);
  48. $this->setResource($resource);
  49. }
  50. /**
  51. * Get the error code
  52. *
  53. * @return int
  54. */
  55. public function getCode()
  56. {
  57. return $this->code;
  58. }
  59. /**
  60. * Set the error code
  61. *
  62. * @param int $code Set to zeroo or a negative value to clear errors
  63. *
  64. * @return void
  65. */
  66. public function setCode($code)
  67. {
  68. if ($code <= 0)
  69. {
  70. $code = 0;
  71. $this->setMessage('');
  72. $this->setResource('');
  73. }
  74. $this->code = $code;
  75. }
  76. /**
  77. * Get the error message
  78. *
  79. * @return string
  80. */
  81. public function getMessage()
  82. {
  83. return $this->message;
  84. }
  85. /**
  86. * Set the error message
  87. *
  88. * @param string $message The error message to set
  89. *
  90. * @return void
  91. */
  92. public function setMessage($message)
  93. {
  94. $this->message = $message;
  95. }
  96. /**
  97. * Get the URI of the resource throwing the error
  98. *
  99. * @return string
  100. */
  101. public function getResource()
  102. {
  103. return $this->resource;
  104. }
  105. /**
  106. * Set the URI of the resource throwing the error
  107. *
  108. * @param string $resource
  109. *
  110. * @return void
  111. */
  112. public function setResource($resource)
  113. {
  114. $this->resource = $resource;
  115. }
  116. /**
  117. * Do we actually have an error?
  118. *
  119. * @return bool
  120. */
  121. public function isError()
  122. {
  123. return ($this->code > 0) || !empty($this->message);
  124. }
  125. }