HintException.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  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 OC;
  27. /**
  28. * Class HintException
  29. *
  30. * An Exception class with the intention to be presented to the end user
  31. *
  32. * @package OC
  33. */
  34. class HintException extends \Exception {
  35. private $hint;
  36. /**
  37. * HintException constructor.
  38. *
  39. * @param string $message The error message. It will be not revealed to the
  40. * the user (unless the hint is empty) and thus
  41. * should be not translated.
  42. * @param string $hint A useful message that is presented to the end
  43. * user. It should be translated, but must not
  44. * contain sensitive data.
  45. * @param int $code
  46. * @param \Exception|null $previous
  47. */
  48. public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) {
  49. $this->hint = $hint;
  50. parent::__construct($message, $code, $previous);
  51. }
  52. /**
  53. * Returns a string representation of this Exception that includes the error
  54. * code, the message and the hint.
  55. *
  56. * @return string
  57. */
  58. public function __toString() {
  59. return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n";
  60. }
  61. /**
  62. * Returns the hint with the intention to be presented to the end user. If
  63. * an empty hint was specified upon instatiation, the message is returned
  64. * instead.
  65. *
  66. * @return string
  67. */
  68. public function getHint() {
  69. if (empty($this->hint)) {
  70. return $this->message;
  71. }
  72. return $this->hint;
  73. }
  74. }