This commit is contained in:
Dave M. 2024-10-02 14:18:35 -04:00
parent 8b1c11676d
commit c56b584140
1 changed files with 38 additions and 44 deletions

View File

@ -60,49 +60,53 @@ trait SearchRequestFromRequestTrait
$field = $fieldName;
}
switch(true) {
case $attribute instanceof SearchGroupBy:
$this->parseAttributeGroupBy($attribute, $field, $propertyName);
break;
case $attribute instanceof SearchWhere:
case $attribute instanceof SearchLike:
case $attribute instanceof SearchManuel:
$value = $this->getValueFromSource($request, $propertyName, $attribute);
if ($value !== null) {
$value = $this->transformValue($property->getAttributes(Attribute\PropertyValueModifier::class), $value);
}
if ($attribute instanceof SearchWhere || $attribute instanceof SearchLike || $attribute instanceof SearchManual) {
if ($attribute->toggle) {
$this->$propertyName = !empty($value);
}
elseif ($value !== null) {
} elseif ($value !== null) {
foreach ($property->getTypes() as $type) {
$enum = $type->type;
if (enum_exists($enum)) {
try {
$this->$propertyName = $type->type::from($value);
}
catch(\ValueError $ex) {
$this->$propertyName = $value instanceof \UnitEnum ? $value : $type->type::from($value);
} catch (\ValueError $ex) {
$cases = implode(', ', array_map(fn($e) => $e->name, $enum::cases()));
throw new \ValueError(
sprintf("Given value '%s' do not exists within enum '%s'. Try one of those values instead : %s", $value, $enum, $cases)
);
}
}
elseif ($type->builtIn) {
} elseif ($type->builtIn) {
$this->$propertyName = $value;
}
}
}
$this->parseAttributeMethod($attribute, $field, $propertyName);
}
elseif ($attribute instanceof SearchOrderBy) {
break;
case $attribute instanceof SearchOrderBy:
if ($value !== null) {
$this->$propertyName = $value;
}
$this->parseAttributeOrderBy($attribute, $field, $propertyName);
}
}
elseif ($attribute instanceof SearchGroupBy) {
$this->parseAttributeGroupBy($attribute, $field, $propertyName);
break;
}
}
}
@ -188,14 +192,4 @@ trait SearchRequestFromRequestTrait
$this->groups[] = $field;
}
}
# @TODO !
/* protected function parseAttributeGroupBy(object $attribute, string $field, string $propertyName,) : void
{
switch ($attribute->order) {
case SearchMethodEnum::GroupBy:
$this->groups[$field];
break;
}
}*/
}