Final Class Yiisoft\Yii\Debug\Api\Debug\Middleware\ResponseDataWrapper
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Psr\ |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| process() | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $responseFactory | \ |
|
| $currentRoute | \ |
|
public function __construct(private DataResponseFactoryInterface $responseFactory, private CurrentRoute $currentRoute) {}
| public \ | ||
| $request | \ |
|
| $handler | \ |
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$data = [
'id' => $this->currentRoute->getArgument('id'),
'data' => null,
'error' => null,
'success' => true,
];
try {
$response = $handler->handle($request);
if (!$response instanceof DataResponse) {
return $response;
}
$data['data'] = $response->getData();
$status = $response->getStatusCode();
if ($status >= 400) {
$data['success'] = false;
}
} catch (NotFoundException $exception) {
$data['success'] = false;
$data['error'] = $exception->getMessage();
$status = Status::NOT_FOUND;
}
return $this->responseFactory->createResponse($data, $status);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.