- Heavy rework on search request handling of entities
This commit is contained in:
1 parent
cb125545c7
commit
a9b9c2cce9
3 files changed
+77
No files matched your search
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\SearchRequest;
|
||||
|
||||
class ParsedSearchParameter
|
||||
{
|
||||
public string|\Stringable $operator;
|
||||
|
||||
public string|\Stringable $condition;
|
||||
|
||||
public function __construct(
|
||||
public readonly SearchMethodEnum $searchMethod,
|
||||
public readonly string|\Stringable $field,
|
||||
public readonly mixed $value,
|
||||
) {}
|
||||
|
||||
public function value() : mixed{
|
||||
return match ($this->searchMethod) {
|
||||
SearchMethodEnum::Like => "%$this->value%",
|
||||
SearchMethodEnum::LikeLeft => "%$this->value",
|
||||
SearchMethodEnum::LikeRight => "$this->value%",
|
||||
default => $this->value,
|
||||
};
|
||||
}
|
||||
|
||||
public function operator() : string {
|
||||
if (isset($this->operator)) {
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
return match ($this->searchMethod) {
|
||||
SearchMethodEnum::Like => SearchRequestInterface::SEARCH_REQUEST_OPERATOR_LIKE,
|
||||
default => SearchRequestInterface::SEARCH_REQUEST_OPERATOR_EQUAL,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public function condition() : string {
|
||||
if (isset($this->condition)) {
|
||||
return $this->condition;
|
||||
}
|
||||
|
||||
return match ($this->searchMethod) {
|
||||
SearchMethodEnum::Like => SearchRequestInterface::SEARCH_REQUEST_CONDITION_OR,
|
||||
default => SearchRequestInterface::SEARCH_REQUEST_CONDITION_AND,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user