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