Skip to end of metadata
Go to start of metadata

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

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Sep 09, 2008

    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

  2. Jan 19, 2009

    I think that these class can really help us in a various situation. Please finish it

  3. Apr 19, 2009

    This proposal is a great idea, i do feel that "Xor", "and", and "nand" would be a good idea also, to allow logical chains of validators.

    Also, this proposal was last updated several months ago. Is this proposal going to move forward? If the creator has lost interest, i would be happy to pick it up and run with it.

  4. Mar 04, 2010

    A few days ago I pushed something like proposed here to my new github repository: http://github.com/bergelmir/Laboratory

  5. Feb 06, 2011

    Archiving this proposal, feel free to recover it when you want to work on it again. For more details see this email.