Skip to content

Commit b79bad0

Browse files
committed
loose attributes work now (requestFormatInstance is now created properly using a stdClass)
1 parent e497148 commit b79bad0

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

app/V1Module/presenters/RegistrationPresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function checkCreateAccount()
165165
* @throws WrongCredentialsException
166166
* @throws InvalidArgumentException
167167
*/
168-
#[FormatAttribute("userRegistration")]
168+
#[FormatAttribute(UserFormat::class)]
169169
public function actionCreateAccount()
170170
{
171171
$req = $this->getMetaRequest();

app/V1Module/presenters/base/BasePresenter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class BasePresenter extends \App\Presenters\BasePresenter
7575
*/
7676
public $logger;
7777

78-
/** @var MetaFormat Processed parameters from the request */
79-
private MetaFormat $requestFormatInstance;
78+
/** @var mixed Processed parameters from the request (MetaFormat or stdClass) */
79+
private mixed $requestFormatInstance;
8080

8181
protected function formatPermissionCheckMethod($action)
8282
{
@@ -236,9 +236,12 @@ private function processParams(ReflectionMethod $reflection)
236236

237237
private function processParamsLoose(array $paramData)
238238
{
239+
$formatInstanceArr = [];
240+
239241
// validate each param
240242
foreach ($paramData as $param) {
241243
$paramValue = $this->getValueFromParamData($param);
244+
$formatInstanceArr[$param->name] = $paramValue;
242245

243246
// check if null
244247
if ($paramValue === null) {
@@ -257,6 +260,9 @@ private function processParamsLoose(array $paramData)
257260
}
258261
}
259262
}
263+
264+
// cast to stdClass
265+
$this->requestFormatInstance = (object)$formatInstanceArr;
260266
}
261267

262268
private function processParamsFormat(string $format)

app/helpers/MetaFormats/FieldFormatDefinition.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private static function recursiveFormatChecker(mixed $value, FormatParser $parse
106106
}
107107

108108
// check whether the validator exists
109+
///TODO: replace this mechanism
109110
$validators = FormatCache::getValidators();
110111
if (!array_key_exists($parsedFormat->format, $validators)) {
111112
throw new InternalServerException("The format {$parsedFormat->format} does not have a validator.");

app/helpers/MetaFormats/MetaRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
class MetaRequest
88
{
99
private Request $baseRequest;
10-
private MetaFormat $requestFormatInstance;
10+
private mixed $requestFormatInstance;
1111

12-
public function __construct(Request $request, MetaFormat $requestFormatInstance)
12+
public function __construct(Request $request, mixed $requestFormatInstance)
1313
{
1414
$this->baseRequest = $request;
1515
$this->requestFormatInstance = $requestFormatInstance;

0 commit comments

Comments
 (0)