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