Skip to content

Commit 4f74a2d

Browse files
committed
improved format validation performance
1 parent d07da17 commit 4f74a2d

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

app/V1Module/presenters/base/BasePresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private function processParamsFormat(string $format, ?array $valueDictionary): M
286286
}
287287

288288
// this throws if the value is invalid
289-
$formatInstance->checkedAssign($fieldName, $value);
289+
$formatInstance->checkedAssignWithSchema($requestParamData, $fieldName, $value);
290290
}
291291

292292
// validate structural constraints

app/helpers/MetaFormats/MetaFormat.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ public function checkedAssign(string $fieldName, mixed $value)
4141
$this->$fieldName = $value;
4242
}
4343

44+
/**
45+
* Tries to assign a value to a field. If the value does not conform to the provided schema, an exception is thrown.
46+
* The exception details why the value does not conform to the format.
47+
* More performant version of checkedAssign.
48+
* @param RequestParamData $requestParamData The schema of the request parameter.
49+
* @param string $fieldName The name of the field.
50+
* @param mixed $value The value to be assigned.
51+
* @throws InvalidApiArgumentException Thrown when the value is not assignable.
52+
*/
53+
public function checkedAssignWithSchema(RequestParamData $requestParamData, string $fieldName, mixed $value)
54+
{
55+
$requestParamData->conformsToDefinition($value);
56+
$this->$fieldName = $value;
57+
}
58+
4459
/**
4560
* Validates the given format.
4661
* @throws InvalidApiArgumentException Thrown when a value is not assignable.

0 commit comments

Comments
 (0)