Added by Thomas Weidner, last edited by Thomas Weidner on Sep 18, 2009  (view change) show comment

Labels

 
(None)

Zend Framework: Zend_Validate_Callback Component Proposal

Proposed Component Name Zend_Validate_Callback
Developer Notes http://framework.zend.com/wiki/display/ZFDEV/Zend_Validate_Callback
Proposers Thomas Weidner
Zend Liaison TBD
Revision 1.0 - 25 April 2009: Initial proposal (wiki revision: 6)

Table of Contents

1. Overview

Zend_Validate_Callback is a validator which allows to use any self written method as validator.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • This component will call any userland method as validator

4. Dependencies on Other Framework Components

  • Zend_Validate

5. Theory of Operation

This component allows to use userland methods as validator which are called by using a callback.

6. Milestones / Tasks

  • Milestone 1: [DONE] Proposal finished
  • Milestone 2: [DONE] Proposal accepted
  • Milestone 3: [DONE] Working implementation
  • Milestone 4: [DONE] Unit tests
  • Milestone 5: [DONE] Documentation
  • Milestone 6: [DONE] Moved to core

7. Class Index

  • Zend_Validate_Callback

8. Use Cases

UC-01

Add a callback

UC-02

Add a callback for a class method

9. Class Skeletons

Looks great. I would have needed it this night though, so can't really wait

This validator will be useful as you don't have to replicate code from existing classes and can use validation functions from other libraries.

As the idea for such a validator has already been approved (see this comment from Wil in the issue mentioned above), I hope Zend_Validate_Callback will make it into the core soon.

I'm sorry to say that, but you're wrong.

I was said that I am NOT allowed to add this new component without writing a proposal.
This component has not been approved for core and the patch has some disadvantages as it should work 1:1 to Zend_Filter_Callback.

I'm sorry to hear that, Thomas, as your proposal actually is an improvement of the original patch (I omitted that in my comment but I noticed it ). Given that Zend_Filter_Callback has proven itself I don't think there is much to consider and wait for (before approving it); may your blog entry get the process going!

really great!

i think this component could accept a feature to catch external exceptions

user could choose group of exception to listen

if "mymethod" throws My_Exception or PEAR_Exception validate catch it, register exception message as error message and returns false

if "mymethod" throws everything else, validate class don't catch it

I'm not sure if such a feature is even allowed.

A validator should ALWAYS return true or false.
Which means that it MUST catch ALL exceptions (generic PHP Exception).
So it would return false for ANY exception as it is an validator.

A validator returning exceptions is not good.

Zend Framework Approval

This proposal is accepted for immediate development in the standard incubator. Please test the callback using is_callable() to ensure it will work with PHP 5.3's Closures.

Can this validator check if a callback is valid ?

e.g.

Please read the comments and answer your question yourself.

Hi Thomas

Then this callback validator isn't usable to check if a value is callable.
I think it is a good idea to add a validator which can check callback parameters but a callback validator have to be usable to check if a value is a valid callback.

Greats

Marc,

this proposal has been under public review for over 3 months.
Do you really think that it's a good way to mock about a proposal which actually has been approved one day ago and where no single line of code exists for now ?

When you don't want to use this component when it's finished simply make your own validator.

View the rest of this thread. Most recent comment: Sep 15, 2009
3 more comments by: Marc Bennewitz (private), Matthew Weier O'Phinney, Thomas Weidner