You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HintException.php 2.4KB

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