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 | * Throw a new exception. |
||
38 | * |
||
39 | * @param string $message Error message |
||
40 | * @param int $code Error code |
||
41 | * @param string $errorType Error type |
||
42 | * @param int $httpStatusCode HTTP status code to send (default = 400) |
||
43 | * @param null|string $hint A helper hint |
||
44 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
45 | */ |
||
46 | public function __construct($message, $code, $errorType, $httpStatusCode = 400, $hint = null, $redirectUri = null) |
||
54 | |||
55 | /** |
||
56 | * Unsupported grant type error. |
||
57 | * |
||
58 | * @return static |
||
59 | */ |
||
60 | public static function unsupportedGrantType() |
||
67 | |||
68 | /** |
||
69 | * Invalid request error. |
||
70 | * |
||
71 | * @param string $parameter The invalid parameter |
||
72 | * @param string|null $hint |
||
73 | * |
||
74 | * @return static |
||
75 | */ |
||
76 | public static function invalidRequest($parameter, $hint = null) |
||
84 | |||
85 | /** |
||
86 | * Invalid client error. |
||
87 | * |
||
88 | * @return static |
||
89 | */ |
||
90 | public static function invalidClient() |
||
96 | |||
97 | /** |
||
98 | * Invalid scope error. |
||
99 | * |
||
100 | * @param string $scope The bad scope |
||
101 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
102 | * |
||
103 | * @return static |
||
104 | */ |
||
105 | public static function invalidScope($scope, $redirectUri = null) |
||
112 | |||
113 | /** |
||
114 | * Invalid credentials error. |
||
115 | * |
||
116 | * @return static |
||
117 | */ |
||
118 | public static function invalidCredentials() |
||
122 | |||
123 | /** |
||
124 | * Server error. |
||
125 | * |
||
126 | * @param $hint |
||
127 | * |
||
128 | * @return static |
||
129 | * |
||
130 | * @codeCoverageIgnore |
||
131 | */ |
||
132 | public static function serverError($hint) |
||
142 | |||
143 | /** |
||
144 | * Invalid refresh token. |
||
145 | * |
||
146 | * @param string|null $hint |
||
147 | * |
||
148 | * @return static |
||
149 | */ |
||
150 | public static function invalidRefreshToken($hint = null) |
||
154 | |||
155 | /** |
||
156 | * Access denied. |
||
157 | * |
||
158 | * @param string|null $hint |
||
159 | * @param string|null $redirectUri |
||
160 | * |
||
161 | * @return static |
||
162 | */ |
||
163 | public static function accessDenied($hint = null, $redirectUri = null) |
||
174 | |||
175 | /** |
||
176 | * @return string |
||
177 | */ |
||
178 | public function getErrorType() |
||
182 | |||
183 | /** |
||
184 | * Generate a HTTP response. |
||
185 | * |
||
186 | * @param \Psr\Http\Message\ResponseInterface $response |
||
187 | * @param bool $useFragment True if errors should be in the URI fragment instead of |
||
188 | * query string |
||
189 | * |
||
190 | * @return \Psr\Http\Message\ResponseInterface |
||
191 | */ |
||
192 | public function generateHttpResponse(ResponseInterface $response, $useFragment = false) |
||
223 | |||
224 | /** |
||
225 | * Get all headers that have to be send with the error response. |
||
226 | * |
||
227 | * @return array Array with header values |
||
228 | */ |
||
229 | public function getHttpHeaders() |
||
256 | |||
257 | /** |
||
258 | * Returns the HTTP status code to send when the exceptions is output. |
||
259 | * |
||
260 | * @return int |
||
261 | */ |
||
262 | public function getHttpStatusCode() |
||
266 | |||
267 | /** |
||
268 | * @return null|string |
||
269 | */ |
||
270 | public function getHint() |
||
274 | } |
||
275 |
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: