Added by Felix De Vliegher, last edited by Felix De Vliegher on Sep 09, 2008  (view change) show comment

Labels

 
(None)

Zend Framework: Zend_Validate_Or Component Proposal

Proposed Component Name Zend_Validate_Or
Developer Notes http://framework.zend.com/wiki/display/ZFDEV/Zend_Validate_Or
Proposers Felix De Vliegher
Zend Liaison TBD
Revision 1.0 - 8 september 2008: Initial Draft. (wiki revision: 6)

Table of Contents

1. Overview

Zend_Validate_Or is a validator that makes it possible to chain other validate instances using the OR logical operation.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • This component will accept (an array of) one or more Zend_Validate_Abstract instances in it's constructor and it's addConditionals() method.
  • This component will throw a Zend_Validate_Exception if isValid() is called and no validators are passed in the constructor or the addConditionals() method.
  • This component will allow for subclassing, having protected properties and methods.
  • This component will return true if at least one of the validators that have been set in this validator returns true.
  • This component will return false and provide the error messages from all failed validators if none of the validators that have been set return true.
  • This component must extend from Zend_Validate_Abstract.

4. Dependencies on Other Framework Components

  • Zend_Validate_Abstract
  • Zend_Exception

5. Theory of Operation

This validator is useful if you want to validate something with the idea that at least one of the validators that have been set in Zend_Validate_Or should return true. So, instead of combining multiple validators with an AND logical operation, you combine the validators with the OR logical operation.

6. Milestones / Tasks

  • Milestone 1: [DONE] Write proposal
  • Milestone 2: Community feedback
  • Milestone 3: Working prototype checked into the incubator supporting use cases #1, #2, ...
  • Milestone 4: Unit tests exist, work, and are checked into SVN.
  • Milestone 5: Initial documentation exists.

7. Class Index

  • Zend_Validate_Or

8. Use Cases

UC-01

Instantiate the class, add some extra validators and validate a value:

UC-02

Add the validator to a form element (setting the validators in the class constructor):

9. Class Skeletons

I like the idea on this a lot. One area needs to be addressed for this to work seamlessly with Zend_Form, however. The use cases you show indicate needing to instantiate concrete validators to add to the OR validator. However, Zend_Form allows you to use short names – just the part following the common prefix – and acts as a factory to instantiate the correct validator from a list of plugin paths. This also makes it trivial to do configuration-based forms.

If you can find a solution for this, the proposal is a no-brainer