1 | <?php |
||
14 | class OAuthServerException extends \Exception |
||
15 | { |
||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | private $httpStatusCode; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $errorType; |
||
25 | |||
26 | /** |
||
27 | * @var null|string |
||
28 | */ |
||
29 | private $hint; |
||
30 | |||
31 | /** |
||
32 | * @var null|string |
||
33 | */ |
||
34 | private $redirectUri; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | private $payload; |
||
40 | |||
41 | /** |
||
42 | * Throw a new exception. |
||
43 | * |
||
44 | * @param string $message Error message |
||
45 | * @param int $code Error code |
||
46 | * @param string $errorType Error type |
||
47 | * @param int $httpStatusCode HTTP status code to send (default = 400) |
||
48 | * @param null|string $hint A helper hint |
||
49 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
50 | */ |
||
51 | public function __construct($message, $code, $errorType, $httpStatusCode = 400, $hint = null, $redirectUri = null) |
||
66 | |||
67 | /** |
||
68 | * Returns the current payload. |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | public function getPayload() |
||
76 | |||
77 | /** |
||
78 | * Updates the current payload. |
||
79 | * |
||
80 | * @param array $payload |
||
81 | */ |
||
82 | public function setPayload(array $payload) |
||
86 | |||
87 | /** |
||
88 | * Unsupported grant type error. |
||
89 | * |
||
90 | * @return static |
||
91 | */ |
||
92 | public static function unsupportedGrantType() |
||
99 | |||
100 | /** |
||
101 | * Invalid request error. |
||
102 | * |
||
103 | * @param string $parameter The invalid parameter |
||
104 | * @param null|string $hint |
||
105 | * |
||
106 | * @return static |
||
107 | */ |
||
108 | public static function invalidRequest($parameter, $hint = null) |
||
116 | |||
117 | /** |
||
118 | * Invalid client error. |
||
119 | * |
||
120 | * @return static |
||
121 | */ |
||
122 | public static function invalidClient() |
||
128 | |||
129 | /** |
||
130 | * Invalid scope error. |
||
131 | * |
||
132 | * @param string $scope The bad scope |
||
133 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
134 | * |
||
135 | * @return static |
||
136 | */ |
||
137 | public static function invalidScope($scope, $redirectUri = null) |
||
144 | |||
145 | /** |
||
146 | * Invalid credentials error. |
||
147 | * |
||
148 | * @return static |
||
149 | */ |
||
150 | public static function invalidCredentials() |
||
154 | |||
155 | /** |
||
156 | * Server error. |
||
157 | * |
||
158 | * @param $hint |
||
159 | * |
||
160 | * @return static |
||
161 | * |
||
162 | * @codeCoverageIgnore |
||
163 | */ |
||
164 | public static function serverError($hint) |
||
174 | |||
175 | /** |
||
176 | * Invalid refresh token. |
||
177 | * |
||
178 | * @param null|string $hint |
||
179 | * |
||
180 | * @return static |
||
181 | */ |
||
182 | public static function invalidRefreshToken($hint = null) |
||
186 | |||
187 | /** |
||
188 | * Access denied. |
||
189 | * |
||
190 | * @param null|string $hint |
||
191 | * @param null|string $redirectUri |
||
192 | * |
||
193 | * @return static |
||
194 | */ |
||
195 | public static function accessDenied($hint = null, $redirectUri = null) |
||
206 | |||
207 | /** |
||
208 | * Invalid grant. |
||
209 | * |
||
210 | * @param string $hint |
||
211 | * |
||
212 | * @return static |
||
213 | */ |
||
214 | public static function invalidGrant($hint = '') |
||
226 | |||
227 | /** |
||
228 | * @return string |
||
229 | */ |
||
230 | public function getErrorType() |
||
234 | |||
235 | /** |
||
236 | * Generate a HTTP response. |
||
237 | * |
||
238 | * @param ResponseInterface $response |
||
239 | * @param bool $useFragment True if errors should be in the URI fragment instead of query string |
||
240 | * @param int $jsonOptions options passed to json_encode |
||
241 | * |
||
242 | * @return ResponseInterface |
||
243 | */ |
||
244 | public function generateHttpResponse(ResponseInterface $response, $useFragment = false, $jsonOptions = 0) |
||
268 | |||
269 | /** |
||
270 | * Get all headers that have to be send with the error response. |
||
271 | * |
||
272 | * @return array Array with header values |
||
273 | */ |
||
274 | public function getHttpHeaders() |
||
301 | |||
302 | /** |
||
303 | * Returns the HTTP status code to send when the exceptions is output. |
||
304 | * |
||
305 | * @return int |
||
306 | */ |
||
307 | public function getHttpStatusCode() |
||
311 | |||
312 | /** |
||
313 | * @return null|string |
||
314 | */ |
||
315 | public function getHint() |
||
319 | } |
||
320 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: