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
Posted by Darby Felton (darby) on 2007-12-21T12:42:34.000+0000
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.
Posted by Wil Sinclair (wil) on 2008-04-18T13:12:02.000+0000
This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.
Posted by Wil Sinclair (wil) on 2008-04-18T16:53:36.000+0000
Darby, what is the status of this issue? Can it be closed now?
Posted by Wil Sinclair (wil) on 2008-04-18T16:55:02.000+0000
Please evaluate and categorize/assign as necessary.
Posted by Andries Seutens (andries) on 2008-04-24T07:49:01.000+0000
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}
Posted by Thomas Weidner (thomas) on 2008-12-08T01:44:02.000+0000
addFilters is actually used in several classes as default behaviour for this. Closing this issue as fixed