43 $filter = $this->_request->getParam(self::FILTER_PARAMETER);
44 if (!is_string($filter)) {
47 $filterArray = $this->
parse($filter);
48 if ($filterArray ===
null) {
52 return $partialResponse;
86 protected function parse($filterString)
88 $length = strlen($filterString);
90 if ($length == 0 || preg_match(
'/[^\w\[\],]+/', $filterString)) {
98 $currentElement =
null;
100 for ($position = 0; $position < $length; $position++) {
102 if (in_array($filterString[$position], [
'[',
']',
','])) {
104 $currentElement = substr($filterString,
$start, $position -
$start);
105 $current[$currentElement] = 1;
109 switch ($filterString[$position]) {
111 $parent[] = $currentElement;
121 $current = array_pop($stack);
123 $current[array_pop($parent)] = $temp;
138 if (!empty($stack)) {
143 $currentElement = substr($filterString,
$start, $position -
$start);
144 $current[$currentElement] = 1;
156 protected function applyFilter(array $responseArray, array $filter)
158 $arrayIntersect =
null;
161 if (!(
bool)count(array_filter(array_keys($responseArray),
'is_string'))) {
162 foreach ($responseArray as $key => &
$item) {
168 return $arrayIntersect;
182 foreach ($arrayIntersect as $key => &
$value) {
186 $value = $this->filterCustomAttributes(
196 return $arrayIntersect;
206 private function filterCustomAttributes(array
$item, array $filter) : array
209 foreach (
$item as $key => $field) {
210 $filterKeys = array_keys($filter);
211 if (in_array($field[AttributeInterface::ATTRIBUTE_CODE], $filterKeys)) {
212 $fieldResult[$key][AttributeInterface::ATTRIBUTE_CODE] = $field[AttributeInterface::ATTRIBUTE_CODE];
213 $fieldResult[$key][AttributeInterface::VALUE] = $field[AttributeInterface::VALUE];
215 if (isset($filter[AttributeInterface::ATTRIBUTE_CODE])) {
216 $fieldResult[$key][AttributeInterface::ATTRIBUTE_CODE] = $field[AttributeInterface::ATTRIBUTE_CODE];
218 if (isset($filter[AttributeInterface::VALUE])) {
219 $fieldResult[$key][AttributeInterface::VALUE] = $field[AttributeInterface::VALUE];
const CUSTOM_ATTRIBUTES_KEY
recursiveArrayIntersectKey(array $array1, array $array2)
applyFilter(array $responseArray, array $filter)
__construct(RestRequest $request)