1 | <?php |
||
32 | abstract class CheckMiddleware extends Middleware { |
||
33 | |||
34 | /** @var string */ |
||
35 | protected $appName; |
||
36 | /** @var IRequest */ |
||
37 | protected $request; |
||
38 | /** @var IURLGenerator */ |
||
39 | private $urlGenerator; |
||
40 | /** @var ILogger */ |
||
41 | protected $logger; |
||
42 | |||
43 | /*** |
||
44 | * Constructor |
||
45 | * |
||
46 | * @param string $appName |
||
47 | * @param IRequest $request |
||
48 | * @param IURLGenerator $urlGenerator |
||
49 | * @param ILogger $logger |
||
50 | */ |
||
51 | 62 | public function __construct( |
|
62 | |||
63 | /** |
||
64 | * If a CheckException is being caught, clients who sent an ajax requests |
||
65 | * get a JSON error response while the others are redirected to an error |
||
66 | * page |
||
67 | * |
||
68 | * @inheritDoc |
||
69 | */ |
||
70 | 11 | public function afterException($controller, $methodName, \Exception $exception) { |
|
82 | |||
83 | /** |
||
84 | * Decides which type of response to send |
||
85 | * |
||
86 | * @param string $message |
||
87 | * @param int $code |
||
88 | * |
||
89 | * @return JSONResponse|RedirectResponse|TemplateResponse |
||
90 | */ |
||
91 | 5 | private function computeResponse($message, $code) { |
|
101 | |||
102 | /** |
||
103 | * Redirects the client to an error page or shows an authentication form |
||
104 | * |
||
105 | * @param string $message |
||
106 | * @param int $code |
||
107 | * |
||
108 | * @return RedirectResponse|TemplateResponse |
||
109 | */ |
||
110 | 4 | private function sendHtmlResponse($message, $code) { |
|
125 | |||
126 | /** |
||
127 | * Shows an authentication form |
||
128 | * |
||
129 | * @return TemplateResponse |
||
130 | */ |
||
131 | 1 | private function sendHtml401() { |
|
141 | |||
142 | /** |
||
143 | * Redirects the client to an error page |
||
144 | * |
||
145 | * @param string $message |
||
146 | * @param int $code |
||
147 | * |
||
148 | * @return RedirectResponse |
||
149 | */ |
||
150 | 3 | private function redirectToErrorPage($message, $code) { |
|
160 | |||
161 | /** |
||
162 | * Returns a JSON response to the client |
||
163 | * |
||
164 | * @param string $message |
||
165 | * @param int $code |
||
166 | * |
||
167 | * @return JSONResponse |
||
168 | */ |
||
169 | 1 | private function sendJsonResponse($message, $code) { |
|
179 | |||
180 | } |
||
181 |