- Still WIP on SearchRequest attributes migration

This commit is contained in:
mcndave committed 2024-04-22 13:54:48 +00:00
1 parent 950df5eb99
commit b38b81d03c
4 files changed
+30 -11

No files matched your search

@@ -3,10 +3,8 @@
namespace Ulmus\SearchRequest;
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\SearchRequest\Attribute\SearchGroupBy;
use Ulmus\SearchRequest\Attribute\SearchOrderBy;
use Ulmus\SearchRequest\Attribute\SearchParameter;
use Ulmus\SearchRequest\Attribute\SearchWhere;
use Ulmus\SearchRequest\Attribute\{ SearchParameter, SearchWhere, SearchOrderBy, SearchGroupBy, SearchRequestParameter, };
trait SearchRequestFromRequestTrait
{
@@ -38,7 +36,20 @@ trait SearchRequestFromRequestTrait
$fieldName = $attribute->field ?? $propertyName;
$queryParamName = $attribute->parameter ?? $propertyName;
$field = \Ulmus\Attribute\Attribute::handleArrayField($fieldName, false);;
# Field could be defined for another entity class
if (is_array($fieldName)) {
$field = \Ulmus\Attribute\Attribute::handleArrayField($fieldName, false);
}
# Default class using it, if SearchRequestParameter is defined
elseif ($classAttributes = $classReflection->getAttributes(SearchRequestParameter::class)) {
$searchRequestAttribute = $classAttributes[0]->newInstance();
$className = $searchRequestAttribute->class;
$field = $className::field($fieldName, $searchRequestAttribute->alias);
}
# Untouched string from the attribute
else {
$field = $fieldName;
}
$value = $queryParams->offsetExists($queryParamName) ? $this->transformValue($attributeList, $queryParams[$queryParamName]) : null;
@@ -57,7 +68,10 @@ trait SearchRequestFromRequestTrait
$this->$propertyName = $value;
}
$this->parseAttributeDefaultOrder($attribute, $field, $propertyName);
$this->parseAttributeOrderBy($attribute, $field, $propertyName);
}
elseif ($attribute instanceof SearchGroupBy) {
$this->parseAttributeGroupBy($attribute, $field, $propertyName);
}
}
}
@@ -104,11 +118,18 @@ trait SearchRequestFromRequestTrait
}
}
protected function parseAttributeDefaultOrder(object $attribute, string $field, mixed $propertyName,) : void
protected function parseAttributeOrderBy(object $attribute, string $field, mixed $propertyName,) : void
{
$this->orders[$field] = $this->$propertyName;
}
protected function parseAttributeGroupBy(object $attribute, string $field, mixed $propertyName,) : void
{
if (! empty($this->$propertyName)) {
$this->groups[] = $field;
}
}
# @TODO !
/* protected function parseAttributeGroupBy(object $attribute, string $field, string $propertyName,) : void
{