ZF-1310: Zend_Filter and Zend_Validate: $filters/$validators param in __construct()

Description

What about to add new optional param to __construct() of Zend_Filter and Zend_Validate? Possible implementation could be like this:


class Zend_Filter {
    public function __construct($filters = array()) {
        if (!is_array($filters) && $filters instanceof Zend_Filter_Interface) {
            $filters = array($filters);
        }
        else {
            throw new Zend_Filter_Exception('$filter must implement Zend_Filter_Interface or must be array of Zend_Filter_Interface');
        }
        foreach ($filters as $filter) {
             $this->addFilter($filter);
        }
    }
    //...
}

And similar code for Zend_Validate.

Comments

Why does extending or wrapping (as in composition) the class not work for this? I'd actually prefer not do this with the constructor of the framework component, but would prefer a separate method.

This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.

Darby, what is the status of this issue? Can it be closed now?

Please evaluate and categorize/assign as necessary.

I wouldn't recommend this in the class construction, instead i'd support having a separate addFilters() method, or simply modifying the existing one to accept a single filter or an array of filters:

``` $filter->addFilters(Array $filters) {coide}

addFilters is actually used in several classes as default behaviour for this. Closing this issue as fixed