- Merges
This commit is contained in:
parent
8b1c11676d
commit
c56b584140
|
@ -60,49 +60,53 @@ trait SearchRequestFromRequestTrait
|
||||||
$field = $fieldName;
|
$field = $fieldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $this->getValueFromSource($request, $propertyName, $attribute);
|
switch(true) {
|
||||||
|
case $attribute instanceof SearchGroupBy:
|
||||||
|
$this->parseAttributeGroupBy($attribute, $field, $propertyName);
|
||||||
|
break;
|
||||||
|
|
||||||
if ($value !== null) {
|
case $attribute instanceof SearchWhere:
|
||||||
$value = $this->transformValue($property->getAttributes(Attribute\PropertyValueModifier::class), $value);
|
case $attribute instanceof SearchLike:
|
||||||
}
|
case $attribute instanceof SearchManuel:
|
||||||
|
|
||||||
if ($attribute instanceof SearchWhere || $attribute instanceof SearchLike || $attribute instanceof SearchManual) {
|
$value = $this->getValueFromSource($request, $propertyName, $attribute);
|
||||||
if ($attribute->toggle) {
|
|
||||||
$this->$propertyName = ! empty($value);
|
|
||||||
}
|
|
||||||
elseif ($value !== null) {
|
|
||||||
foreach($property->getTypes() as $type) {
|
|
||||||
$enum = $type->type;
|
|
||||||
|
|
||||||
if (enum_exists($enum)) {
|
if ($value !== null) {
|
||||||
try {
|
$value = $this->transformValue($property->getAttributes(Attribute\PropertyValueModifier::class), $value);
|
||||||
$this->$propertyName = $type->type::from($value);
|
}
|
||||||
|
|
||||||
|
if ($attribute->toggle) {
|
||||||
|
$this->$propertyName = !empty($value);
|
||||||
|
} elseif ($value !== null) {
|
||||||
|
foreach ($property->getTypes() as $type) {
|
||||||
|
$enum = $type->type;
|
||||||
|
|
||||||
|
if (enum_exists($enum)) {
|
||||||
|
try {
|
||||||
|
$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) {
|
||||||
|
$this->$propertyName = $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) {
|
|
||||||
$this->$propertyName = $value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->parseAttributeMethod($attribute, $field, $propertyName);
|
$this->parseAttributeMethod($attribute, $field, $propertyName);
|
||||||
}
|
break;
|
||||||
elseif ($attribute instanceof SearchOrderBy) {
|
|
||||||
if ($value !== null) {
|
case $attribute instanceof SearchOrderBy:
|
||||||
$this->$propertyName = $value;
|
if ($value !== null) {
|
||||||
|
$this->$propertyName = $value;
|
||||||
|
}
|
||||||
|
|
||||||
$this->parseAttributeOrderBy($attribute, $field, $propertyName);
|
$this->parseAttributeOrderBy($attribute, $field, $propertyName);
|
||||||
}
|
break;
|
||||||
}
|
|
||||||
elseif ($attribute instanceof SearchGroupBy) {
|
|
||||||
$this->parseAttributeGroupBy($attribute, $field, $propertyName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,14 +192,4 @@ trait SearchRequestFromRequestTrait
|
||||||
$this->groups[] = $field;
|
$this->groups[] = $field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# @TODO !
|
|
||||||
/* protected function parseAttributeGroupBy(object $attribute, string $field, string $propertyName,) : void
|
|
||||||
{
|
|
||||||
switch ($attribute->order) {
|
|
||||||
case SearchMethodEnum::GroupBy:
|
|
||||||
$this->groups[$field];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue