1
0

HintException.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCP;
  27. /**
  28. * Class HintException
  29. *
  30. * An Exception class with the intention to be presented to the end user
  31. *
  32. * @package OCP
  33. * @since 23.0.0
  34. */
  35. class HintException extends \Exception {
  36. private $hint;
  37. /**
  38. * HintException constructor.
  39. *
  40. * @since 23.0.0
  41. * @param string $message The error message. It will be not revealed to the
  42. * the user (unless the hint is empty) and thus
  43. * should be not translated.
  44. * @param string $hint A useful message that is presented to the end
  45. * user. It should be translated, but must not
  46. * contain sensitive data.
  47. * @param int $code
  48. * @param \Exception|null $previous
  49. */
  50. public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) {
  51. $this->hint = $hint;
  52. parent::__construct($message, $code, $previous);
  53. }
  54. /**
  55. * Returns a string representation of this Exception that includes the error
  56. * code, the message and the hint.
  57. *
  58. * @since 23.0.0
  59. * @return string
  60. */
  61. public function __toString(): string {
  62. return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n";
  63. }
  64. /**
  65. * Returns the hint with the intention to be presented to the end user. If
  66. * an empty hint was specified upon instantiation, the message is returned
  67. * instead.
  68. *
  69. * @since 23.0.0
  70. * @return string
  71. */
  72. public function getHint(): string {
  73. if (empty($this->hint)) {
  74. return $this->message;
  75. }
  76. return $this->hint;
  77. }
  78. }