- Added multiple parameters on SearchParameter
This commit is contained in:
parent
bbfd7c02b4
commit
0c8591f238
|
@ -8,7 +8,7 @@ use Ulmus\SearchRequest\SearchMethodEnum;
|
|||
class SearchLike extends SearchParameter
|
||||
{
|
||||
public function __construct(
|
||||
public ? string $parameter = null,
|
||||
public null|string|array $parameter = null,
|
||||
public null|string|\Stringable|array $field = null,
|
||||
public bool $toggle = false,
|
||||
public SearchMethodEnum $method = SearchMethodEnum::Like,
|
||||
|
|
|
@ -12,7 +12,7 @@ class SearchOrderBy extends SearchParameter
|
|||
public const DESCENDING = "DESC";
|
||||
|
||||
public function __construct(
|
||||
public ? string $parameter = null,
|
||||
public null|string|array $parameter = null,
|
||||
public null|string|\Stringable|array $field = null,
|
||||
public null|SearchMethodEnum $order = null,
|
||||
public string $description = "",
|
||||
|
|
|
@ -17,4 +17,9 @@ abstract class SearchParameter {
|
|||
{
|
||||
return is_array($this->source) ? $this->source : [ $this->source ];
|
||||
}
|
||||
|
||||
public function getParameters() : array
|
||||
{
|
||||
return array_filter((array) $this->parameter);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ use Ulmus\SearchRequest\SearchMethodEnum;
|
|||
class SearchWhere extends SearchParameter
|
||||
{
|
||||
public function __construct(
|
||||
public ? string $parameter = null,
|
||||
public null|string|array $parameter = null,
|
||||
public null|string|\Stringable|array $field = null,
|
||||
public bool $toggle = false,
|
||||
public SearchMethodEnum $method = SearchMethodEnum::Where,
|
||||
|
|
|
@ -93,24 +93,28 @@ trait SearchRequestFromRequestTrait
|
|||
|
||||
protected function getValueFromSource(RequestInterface $request, string $propertyName, SearchParameter $attribute) : mixed
|
||||
{
|
||||
$queryParamName = $attribute->parameter ?? $propertyName;
|
||||
$queryParamName = $attribute->getParameters() ?? [ $propertyName ];
|
||||
|
||||
foreach($attribute->getSources() as $source) {
|
||||
switch($source) {
|
||||
case PropertyValueSource::QueryParams:
|
||||
$queryParams = new \ArrayObject(array_filter($request->getQueryParams(), function($i) { return ! is_null($i) && $i !== ""; }));
|
||||
|
||||
if ($queryParams->offsetExists($queryParamName)) {
|
||||
return $queryParams[$queryParamName];
|
||||
foreach($queryParamName as $param) {
|
||||
if ($queryParams->offsetExists($param)) {
|
||||
return $queryParams[$param];
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PropertyValueSource::RequestAttribute:
|
||||
$fromAttribute = $request->getAttribute($queryParamName, null);
|
||||
foreach($queryParamName as $param) {
|
||||
$fromAttribute = $request->getAttribute($param, null);
|
||||
|
||||
if ($fromAttribute !== null) {
|
||||
return $fromAttribute;
|
||||
if ($fromAttribute !== null) {
|
||||
return $fromAttribute;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue