Zend Framework

Zend_Filter_Input with inputNamespace having filters and validators getting the wrong type...

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.8.0
  • Component/s: Zend_Filter_Input
  • Labels:
    None
  • Fix Version Priority:
    Should Have

Description

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

$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

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:

$options = array(
'inputNamespace' => array(
'filter' => 'My_Filter',
'validate' => 'My_Validate'
),
);

Activity

Hide
Jordan Raub added a comment -

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"

Show
Jordan Raub added a comment - 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"
Hide
Carlton Gibson added a comment -

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:

case self::INPUT_NAMESPACE:
      $this->addFilterPrefixPath($value['filter'], str_replace('_', DIRECTORY_SEPARATOR, $value['filter']) );
      $this->addValidatorPrefixPath($value['validate'], str_replace('_', DIRECTORY_SEPARATOR, $value['validate']) );
      break;

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

Show
Carlton Gibson added a comment - 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:
case self::INPUT_NAMESPACE:
      $this->addFilterPrefixPath($value['filter'], str_replace('_', DIRECTORY_SEPARATOR, $value['filter']) );
      $this->addValidatorPrefixPath($value['validate'], str_replace('_', DIRECTORY_SEPARATOR, $value['validate']) );
      break;
All this does though is replicate what's going on in the depreciated method...
Hide
Carlton Gibson added a comment -

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.

Show
Carlton Gibson added a comment - 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.
Hide
Benjamin Eberlei added a comment -

Fixed in trunk as of 12670.

Show
Benjamin Eberlei added a comment - Fixed in trunk as of 12670.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
Not Specified
Original Estimate - Not Specified
Remaining:
0m
Remaining Estimate - 0 minutes
Logged:
20m
Time Spent - 20 minutes