ZF-3100: Zend_Filter_Input with inputNamespace having filters and validators getting the wrong type...


I have a date filter called My_Filter_Date and I need to use this before the standard Zend_Validate_Date validation, in ZF 1.5.1 this happens {quote} $filters = array( 'dob' => array('Date') ); $validators = array( 'dob' => array('Date') ); $data = array( 'dob' => '1990-01-01' ), $options = array( 'inputNamespace' => array('My_Filter', 'My_Validate'), ); $filter = new Zend_Filter_Input($filters, $validators, $data, $options); $filter->process(); //throws "Zend_Filter_Exception: Class based on basename 'Date' must implement the 'Zend_Validate_Interface' interface" from line 914 Zend/Filter/Input.php {quote}

line 908 of Zend/Filter/Input.php pulls out the wrong Class name from the method getPluginLoader since adding inputNamespace doesn't specify which type, either filter or validator or maybe both, the specified directory holds.

maybe it would be useful to add a key to the inputNamespace options array like so: {quote} $options = array( 'inputNamespace' => array( 'filter' => 'My_Filter', 'validate' => 'My_Validate' ), ); {quote}


This also breaks when I have a filter and a validator for the same thing... i.e. My_Filter_SSN and My_Validate_SSN

exception thrown as "Zend_Filter_Exception: Class based on basename 'SSN' must implement the 'Zend_Filter_Interface' interface"

I noticed a related problem that setOptions() calls addNamespace() for the INPUT_NAMESPACE case (ZFI lines 512-514): addNamespace has been depreciated though...

Applying Jordan's suggestion above for a nested array as the inputNamespace value, the following would work:

      $this->addFilterPrefixPath($value['filter'], str_replace('_', DIRECTORY_SEPARATOR, $value['filter']) );
      $this->addValidatorPrefixPath($value['validate'], str_replace('_', DIRECTORY_SEPARATOR, $value['validate']) );

All this does though is replicate what's going on in the depreciated method...

This is a patchfile which retains BC.

It adds validatorNamespace and filterNamespace to the available options so you can use those instead of inputNamespace.

It calls the appropriate add --- PrefixPath method converting the prefix to a path in the process.

Fixed in trunk as of 12670.