Cleanup: Validation
- Proposal for Agavi 2.0
- Authors
Some parts of the validation engine are a bit of a mess, handling of arrays in particular. My suggestion is a virtual filesystem, rather than a virtual "array path."
Consider the following, where the request parameter "scalar" is any scalar value, and "array" is an array with the following structure:
$array = array(
'test' => array(
'one' => '1',
'two' => '2'
),
'value' => 'x'
);
<validator> <arguments> <!-- AgaviValidator::getData('array') returns the entire array as shown above for the validator to parse. --> <argument>array</argument> <!-- AgaviValidator::getData('array/test') returns the array within the 'test' index of 'array' --> <argument>array/test</argument> <!-- AgaviValidator::getData('array/value') returns 'x' --> <argument>array/value</argument> <!-- AgaviValidator::getData('scalar') returns the value of the scalar --> <argument>scalar</argument> </arguments> </validator>
Another idea might be to expose the array as a DOM tree, which would make parsing the values in <argument> even easier, as they could just be considered xpath.
The obvious downside to all of this is that all validators will have to support arrays as input in their execute() method. Better ideas are welcome for this part especially, but also for the whole thing of course.
(It's worth noting that a system similar to this was in place at some point, but it was quite odd and had to do with setting base paths and things like that -- not exactly easy to use nor intuitive.)

