Skip to end of metadata
Go to start of metadata

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

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Apr 29, 2009

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

  2. Jun 07, 2009

    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.

    1. Jun 07, 2009

      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.

      1. Jun 08, 2009

        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!

  3. Jun 11, 2009

    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

    1. Jun 12, 2009

      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.

  4. Jul 14, 2009

    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.
  5. Jul 15, 2009

    Can this validator check if a callback is valid ?

    e.g.

    1. Jul 16, 2009

      Please read the comments and answer your question yourself.

      1. Jul 16, 2009

        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

        1. Jul 16, 2009

          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.

          1. Jul 16, 2009

            Hi Thomas

            Sorry if I expressed not clearly in my last comments.
            I would only say that a validator named callback should used to validate
            callbacks (with the isValid method).

            The current version is only working as a wrapper for own functions.

            Greats

            1. Sep 15, 2009

              Marc – please read the proposal carefully. The intention has been clear all along: this is a validator that uses a callback in order to perform its work. We have similar functionality with Zend_Filter_Callback (which uses a callback to perform the filtering) and Zend_Form_Decorator_Callback (which uses a callback in order to render an element). What I'm getting at is that the name is consistent with usage elsewhere in the framework.

              To validate a callback, is_callable exits, and we'd likely call such a validator Zend_Validate_IsCallable.

              1. Sep 15, 2009

                As note:
                There is a Zend_Validate_IsCallable proposal since several weeks.
                I'm just not finished with it until now.

                Also I am still not sure in which cases such a IsCallable validator would make sense.