- Still working on SearchRequest for optimized and more advanced query manipulations
- Minor bugfixes in DatasetHandler and ObjectInstanciator
This commit is contained in:
1 parent
5d32d9f635
commit
709ed63323
5 files changed
+71
-34
No files matched your search
@@ -23,6 +23,11 @@ trait SearchRequestFromRequestTrait
|
||||
|
||||
protected array $parsedParameters = [];
|
||||
|
||||
public function toArray() : array
|
||||
{
|
||||
return json_decode(json_encode($this), true);
|
||||
}
|
||||
|
||||
public function fromParsedParameters(Repository $repository) : SearchRequestInterface
|
||||
{
|
||||
foreach($this->parsedParameters as $property => $param) {
|
||||
@@ -69,6 +74,7 @@ trait SearchRequestFromRequestTrait
|
||||
$this->applyConditions(
|
||||
fn($propertyName) => $data["$propertyName:condition"] ?? null
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -171,7 +177,7 @@ trait SearchRequestFromRequestTrait
|
||||
|
||||
case $attribute instanceof SearchOrderBy:
|
||||
if ($value !== null) {
|
||||
$this->$propertyName = $value;
|
||||
$this->$propertyName = $this->parseValue($property, $value);
|
||||
}
|
||||
|
||||
$this->parseAttributeOrderBy($attribute, $field, $propertyName);
|
||||
@@ -184,24 +190,7 @@ trait SearchRequestFromRequestTrait
|
||||
$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 || $value instanceof \Stringable ) {
|
||||
$this->$propertyName = $value;
|
||||
}
|
||||
}
|
||||
$this->$propertyName = $this->parseValue($property, $value);
|
||||
}
|
||||
|
||||
$this->parseAttributeMethod($attribute, $field, $propertyName);
|
||||
@@ -211,6 +200,28 @@ trait SearchRequestFromRequestTrait
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseValue(\Notes\Common\ReflectedProperty $property, mixed $value) : mixed
|
||||
{
|
||||
foreach ($property->getTypes() as $type) {
|
||||
$enum = $type->type;
|
||||
|
||||
if (enum_exists($enum)) {
|
||||
try {
|
||||
return $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 || $value instanceof \Stringable ) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getEntityField(array|string $fieldName) : string|\Stringable
|
||||
{
|
||||
# Field could be defined for another entity class
|
||||
|
||||
Reference in new issue
Block a user