zendframework/zf2 — pull request #3359 by iwalz (2013-01-06 21:25:39+00:00)
Title: Added filter possibility

I often came around with the ClassMethods hydrator, that there are parts in the hydration that shouldn't be there. Or related to #3352 that the method definition does not match.
Those few lines will give you the possibility, to easily ignore the "has" methods in your hydration e.g:
```php
$hydrator = new ClassMethods(false);
$hydrator->removeFilter('has');
$hydrator->extract($myObject);
```

Or you can easily add custom filters:
```php
$hydrator = new ClassMethods(false);
$hydrator->addFilter('serviceLocator',
function($property) {
list($class, $method) = explode('::', $property);
// do not hydrate getServiceLocator
if ($method === 'getServiceLocator') {
return false;
}
return true;
}, FilterComposite::CONDITION_AND
);
$hydrator->extract($myObject);
```

Heavily tested code may have more getters and setters than necessary, but if you want to transform your objects to the userland, you may want to strip some getters and setters.

Internally, there are 2 arrays, where the composition is working on. The "OR", where only 1 method from that collection has to return true and on the other hand, the "AND" condition, where all filters has to return true to get hydrated. With this implementation, #3352 can be easily implemented as another filter. If you want me to do so, close #3352 and give me a hint here. What do you think about the idea/use-case/implementation? If you like the idea behind, I can make it work the abstract-hydrator too.