/** * Extracts the filters from the JSON object. * * @param $data * * @throws \Exception * * @return Filter */ private function extractJSONFilters($data) { $filter = new Filter(); if (property_exists($data, 'property')) { if (strpos($data->property, '.') !== false) { $associations = explode('.', $data->property); $property = array_pop($associations); $filter->setAssociation(implode('.', $associations)); $filter->setProperty($property); } else { $filter->setAssociation(null); $filter->setProperty($data->property); } } elseif (property_exists($data, "subfilters")) { if (property_exists($data, 'type')) { $filter->setType(strtolower($data->type)); } if (is_array($data->subfilters)) { $subfilters = []; foreach ($data->subfilters as $subfilter) { $subfilters[] = $this->extractJSONFilters($subfilter); } $filter->setSubFilters($subfilters); return $filter; } else { throw new \Exception("The subfilters must be an array of objects"); } } else { throw new \Exception('You need to set the filter property'); } if (property_exists($data, 'operator')) { $filter->setOperator($data->operator); } else { $filter->setOperator(Filter::OPERATOR_EQUALS); } if (property_exists($data, 'value')) { $filter->setValue($this->getFilterValueFromUrl($data->value)); } else { throw new \Exception('No value specified'); } return $filter; }