From a8276c1213eb5289d8e7a2e096bc42f5bc4def37 Mon Sep 17 00:00:00 2001 From: David Windell Date: Tue, 1 Feb 2022 16:14:43 +0000 Subject: [PATCH] Fix wildcard value filter support --- src/Edge/Search/AbstractSearcher.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Edge/Search/AbstractSearcher.php b/src/Edge/Search/AbstractSearcher.php index cabb10c..4d0d4d2 100644 --- a/src/Edge/Search/AbstractSearcher.php +++ b/src/Edge/Search/AbstractSearcher.php @@ -25,7 +25,7 @@ abstract class AbstractSearcher implements SearcherInterface /** * @var array|FilterInterface[] */ - protected $valuefilters = array(); + protected $valuefilters = []; public function __construct() @@ -89,11 +89,11 @@ public function getConverters() public function addValueFilter($field, FilterInterface $filter) { - $this->valuefilters[$field] = $filter; + $this->valuefilters[$field][] = $filter; return $this; } - public function hasValueFilter($field) + public function hasValueFilters($field) { return array_key_exists($field, $this->valuefilters) || array_key_exists('*', $this->valuefilters); @@ -103,10 +103,10 @@ public function hasValueFilter($field) * Get value filter for field * * @param string $field - * @return FilterInterface + * @return array|FilterInterface[] * @throws Exception\InvalidArgumentException */ - public function getValueFilter($field) + public function getValueFilters($field) { if (isset($this->valuefilters[$field])) { return $this->valuefilters[$field]; @@ -123,7 +123,7 @@ public function getValueFilter($field) return $this->valuefilters['*']; } - public function removeValueFilter($field) + public function removeValueFilters($field) { unset($this->valuefilters[$field]); return $this; @@ -131,8 +131,10 @@ public function removeValueFilter($field) protected function prepareValue($value, $field) { - if ($this->hasValueFilter($field)) { - $value = $this->getValueFilter($field)->filter($value); + if ($this->hasValueFilters($field)) { + foreach ($this->getValueFilters($field) as $filter) { + $value = $filter->filter($value); + } } $mappedField = $this->getMappedField($field); @@ -143,7 +145,7 @@ protected function prepareValue($value, $field) /** * Get mapped field - * + * * @param string $name * @return array * @throws Exception\InvalidArgumentException @@ -173,4 +175,4 @@ public function getMappedField($name) * @return mixed */ abstract protected function handleTypeConversions($value, $type); -} \ No newline at end of file +}