- Merges
This commit is contained in:
		
							parent
							
								
									8b1c11676d
								
							
						
					
					
						commit
						c56b584140
					
				| @ -60,49 +60,53 @@ trait SearchRequestFromRequestTrait | ||||
|                     $field = $fieldName; | ||||
|                 } | ||||
| 
 | ||||
|                 $value = $this->getValueFromSource($request, $propertyName, $attribute); | ||||
|                 switch(true) { | ||||
|                     case $attribute instanceof SearchGroupBy: | ||||
|                         $this->parseAttributeGroupBy($attribute, $field, $propertyName); | ||||
|                         break; | ||||
| 
 | ||||
|                 if ($value !== null) { | ||||
|                     $value = $this->transformValue($property->getAttributes(Attribute\PropertyValueModifier::class), $value); | ||||
|                 } | ||||
|                     case $attribute instanceof SearchWhere: | ||||
|                     case $attribute instanceof SearchLike: | ||||
|                     case $attribute instanceof SearchManuel: | ||||
| 
 | ||||
|                 if ($attribute instanceof SearchWhere || $attribute instanceof SearchLike || $attribute instanceof SearchManual) { | ||||
|                     if ($attribute->toggle) { | ||||
|                         $this->$propertyName = ! empty($value); | ||||
|                     } | ||||
|                     elseif ($value !== null) { | ||||
|                         foreach($property->getTypes() as $type) { | ||||
|                             $enum = $type->type; | ||||
|                         $value = $this->getValueFromSource($request, $propertyName, $attribute); | ||||
| 
 | ||||
|                             if (enum_exists($enum)) { | ||||
|                                 try { | ||||
|                                     $this->$propertyName = $type->type::from($value); | ||||
|                         if ($value !== null) { | ||||
|                             $value = $this->transformValue($property->getAttributes(Attribute\PropertyValueModifier::class), $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); | ||||
|                 } | ||||
|                 elseif ($attribute instanceof SearchOrderBy) { | ||||
|                     if ($value !== null) { | ||||
|                         $this->$propertyName = $value; | ||||
|                         $this->parseAttributeMethod($attribute, $field, $propertyName); | ||||
|                         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; | ||||
|         } | ||||
|     }*/ | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user