public function FilterComposite::addFilter in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/zendframework/zend-hydrator/src/Filter/FilterComposite.php \Zend\Hydrator\Filter\FilterComposite::addFilter()
Add a filter to the composite. Has to be indexed with $name in order to identify a specific filter.
This example will exclude all methods from the hydration, that starts with 'getService' <code> $composite->addFilter('exclude', function ($method) { if (preg_match('/^getService/', $method) { return false; } return true; }, FilterComposite::CONDITION_AND ); </code>
Parameters
string $name:
callable|FilterInterface $filter:
int $condition Can be either: FilterComposite::CONDITION_OR or FilterComposite::CONDITION_AND
Return value
Throws
File
- vendor/
zendframework/ zend-hydrator/ src/ Filter/ FilterComposite.php, line 97
Class
Namespace
Zend\Hydrator\FilterCode
public function addFilter($name, $filter, $condition = self::CONDITION_OR) {
if (!is_callable($filter) && !$filter instanceof FilterInterface) {
throw new InvalidArgumentException('The value of ' . $name . ' should be either a callable or ' . 'an instance of Zend\\Stdlib\\Hydrator\\Filter\\FilterInterface');
}
if ($condition === self::CONDITION_OR) {
$this->orFilter[$name] = $filter;
}
elseif ($condition === self::CONDITION_AND) {
$this->andFilter[$name] = $filter;
}
return $this;
}