Skip to content

Commit c164fe0

Browse files
eceltovkrulis-martin
authored andcommitted
path params are now checked
1 parent 314cf1b commit c164fe0

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

app/V1Module/presenters/base/BasePresenter.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,6 @@ private function processParamsLoose(array $paramData)
226226
{
227227
// validate each param
228228
foreach ($paramData as $param) {
229-
///TODO: path parameters are not checked yet
230-
if ($param->type == Type::Path) {
231-
continue;
232-
}
233-
234229
$paramValue = $this->getValueFromParamData($param);
235230

236231
// this throws when it does not conform
@@ -265,11 +260,6 @@ private function processParamsFormat(string $format, ?array $valueDictionary): M
265260
$value = null;
266261
// top-level format
267262
if ($valueDictionary === null) {
268-
///TODO: path parameters are not checked yet
269-
if ($requestParamData->type == Type::Path) {
270-
continue;
271-
}
272-
273263
$value = $this->getValueFromParamData($requestParamData);
274264
// nested format
275265
} else {
@@ -302,7 +292,7 @@ private function processParamsFormat(string $format, ?array $valueDictionary): M
302292
}
303293

304294
/**
305-
* Calls either getPostField or getQueryField based on the provided metadata.
295+
* Calls either getPostField, getQueryField or getPathField based on the provided metadata.
306296
* @param \App\Helpers\MetaFormats\RequestParamData $paramData Metadata of the request parameter.
307297
* @throws \App\Exceptions\InternalServerException Thrown when an unexpected parameter location was set.
308298
* @return mixed Returns the value from the request.
@@ -314,6 +304,8 @@ private function getValueFromParamData(RequestParamData $paramData): mixed
314304
return $this->getPostField($paramData->name, required: $paramData->required);
315305
case Type::Query:
316306
return $this->getQueryField($paramData->name, required: $paramData->required);
307+
case Type::Path:
308+
return $this->getPathField($paramData->name);
317309
default:
318310
throw new InternalServerException("Unknown parameter type: {$paramData->type->name}");
319311
}
@@ -356,6 +348,15 @@ private function getQueryField($param, $required = true)
356348
return $value;
357349
}
358350

351+
private function getPathField($param)
352+
{
353+
$value = $this->getParameter($param);
354+
if ($value === null) {
355+
throw new BadRequestException("Missing required path field $param");
356+
}
357+
return $value;
358+
}
359+
359360
protected function logUserAction($code = IResponse::S200_OK)
360361
{
361362
if ($this->getUser()->isLoggedIn()) {

0 commit comments

Comments
 (0)