Skip to content

Commit

Permalink
Query configurator check 0 and false
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Beranek committed Aug 15, 2024
1 parent bb4594e commit 2a61196
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Output/Configurator/QueryConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public function __construct(

public function validateSchema(): bool
{
$getParams = $this->request->getQuery();
return isset($getParams[$this->schemaValidateParam]);
$getParam = $this->request->getQuery($this->schemaValidateParam);
return $getParam !== null && $getParam !== '0' && $getParam !== 'false';
}

public function showErrorDetail(): bool
{
$getParams = $this->request->getQuery();
return isset($getParams[$this->errorDetailParam]);
$getParam = $this->request->getQuery($this->errorDetailParam);
return $getParam !== null && $getParam !== '0' && $getParam !== 'false';
}
}
6 changes: 3 additions & 3 deletions src/Presenters/ApiPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function run(Request $request): IResponse
$paramsProcessor = new ParamsProcessor($handler->params());
if ($paramsProcessor->isError()) {
$this->response->setCode(Response::S400_BAD_REQUEST);
if ($this->outputConfigurator->showErrorDetail($request)) {
if ($this->outputConfigurator->showErrorDetail()) {
$response = new JsonResponse(['status' => 'error', 'message' => 'wrong input', 'detail' => $paramsProcessor->getErrors()]);
} else {
$response = new JsonResponse(['status' => 'error', 'message' => 'wrong input']);
Expand All @@ -99,7 +99,7 @@ public function run(Request $request): IResponse
$response = $handler->handle($params);
$code = $response->getCode();

if ($this->outputConfigurator->validateSchema($request)) {
if ($this->outputConfigurator->validateSchema()) {
$outputValid = count($handler->outputs()) === 0; // back compatibility for handlers with no outputs defined
$outputValidatorErrors = [];
foreach ($handler->outputs() as $output) {
Expand All @@ -120,7 +120,7 @@ public function run(Request $request): IResponse
}
}
} catch (Throwable $exception) {
if ($this->outputConfigurator->showErrorDetail($request)) {
if ($this->outputConfigurator->showErrorDetail()) {
$response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error', 'detail' => $exception->getMessage()]);
} else {
$response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error']);
Expand Down

0 comments on commit 2a61196

Please sign in to comment.