mirror of
https://github.com/getformwork/formwork.git
synced 2025-01-17 05:28:20 +01:00
Add ResponseInterface::prepare()
step to pre-process responses according to the request
This commit is contained in:
parent
cb81de616f
commit
1f6937e54c
@ -138,9 +138,11 @@ final class App
|
||||
|
||||
DynamicFieldValue::$vars = $this->container->call(require $this->config()->get('system.fields.dynamic.vars.file'));
|
||||
|
||||
$request = $this->request();
|
||||
|
||||
$response = $this->router()->dispatch();
|
||||
|
||||
$response->send();
|
||||
$response->prepare($request)->send();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
@ -34,11 +34,11 @@ class ErrorHandlers
|
||||
Response::cleanOutputBuffers();
|
||||
|
||||
if ($this->request->isXmlHttpRequest()) {
|
||||
JsonResponse::error('Error', $responseStatus)->send();
|
||||
JsonResponse::error('Error', $responseStatus)->prepare($this->request)->send();
|
||||
} else {
|
||||
$view = $this->viewFactory->make('errors.error', ['status' => $responseStatus->code(), 'message' => $responseStatus->message(), 'throwable' => $throwable]);
|
||||
$response = new Response($view->render(), $responseStatus);
|
||||
$response->send();
|
||||
$response->prepare($this->request)->send();
|
||||
// Don't exit, otherwise the error will not be logged
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,14 @@ class Response implements ResponseInterface
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare response according to the given HTTP request
|
||||
*/
|
||||
public function prepare(Request $request): static
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send HTTP status
|
||||
*/
|
||||
|
@ -35,6 +35,11 @@ interface ResponseInterface extends ArraySerializable
|
||||
*/
|
||||
public function headers(): array;
|
||||
|
||||
/**
|
||||
* Prepare response according to the given HTTP request
|
||||
*/
|
||||
public function prepare(Request $request): static;
|
||||
|
||||
/**
|
||||
* Send HTTP status
|
||||
*/
|
||||
|
@ -224,6 +224,7 @@ abstract class AbstractController extends BaseAbstractController
|
||||
if (!$this->user()->permissions()->has($permission)) {
|
||||
$this->container->build(ErrorsController::class)
|
||||
->forbidden()
|
||||
->prepare($this->request)
|
||||
->send();
|
||||
exit;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class PanelServiceLoader implements ResolutionAwareServiceLoaderInterface
|
||||
if ($service->isLoggedIn() && $this->config->get('system.errors.setHandlers')) {
|
||||
$errorsController = $this->container->build(ErrorsController::class);
|
||||
set_exception_handler(function (Throwable $throwable) use ($errorsController): never {
|
||||
$errorsController->internalServerError($throwable)->send();
|
||||
$errorsController->internalServerError($throwable)->prepare($this->request)->send();
|
||||
throw $throwable;
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user