private function initFilters(array $filters)
{
$result = [];
$fm = $this->getFilterManager();
foreach ($filters as $alias => $options) {
$option = null;
if (is_array($options)) {
if (!isset($options['name'])) {
throw new Exception\InvalidArgumentException('Filter "' . $alias . '" required option "name"');
}
$name = $options['name'];
$option = isset($options['option']) ? $options['option'] : null;
} elseif (is_string($options)) {
$name = $options;
unset($options);
}
if (is_numeric($alias)) {
$alias = $name;
}
// Filter Id should have optional filter indicator "?"
$filterId = ltrim($alias, '?');
if (!$fm->has($filterId)) {
if (is_array($option) && !empty($option)) {
$r = new \ReflectionClass($name);
$filter = $r->newInstanceArgs($option);
} elseif ($option) {
$filter = new $name($option);
} else {
$filter = new $name();
}
$fm->set($filterId, $filter);
}
$result[] = $alias;
}
return $result;
}