Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

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: 7)

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

]]></ac:plain-text-body></ac:macro>

]]></ac:plain-text-body></ac:macro>

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

    <p>Looks great. I would have needed it this night though, so can't really wait <ac:emoticon ac:name="wink" /></p>

  2. Jun 07, 2009

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

    <p>As the idea for such a validator has already been approved (see this <a href="http://framework.zend.com/issues/browse/ZF-2268?focusedCommentId=28470">comment from Wil</a> in the issue mentioned above), I hope Zend_Validate_Callback will make it into the core soon.</p>

    1. Jun 07, 2009

      <p>I'm sorry to say that, but you're wrong.</p>

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

      1. Jun 08, 2009

        <p>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 <ac:emoticon ac:name="wink" />). 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!</p>

  3. Jun 11, 2009

    <p>really great!</p>

    <p>i think this component could accept a feature to catch external exceptions</p>

    <p>user could choose group of exception to listen</p>

    <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
    $validator = new Zend_Validator_Callback('mymethod');
    $validator->catchException('My_Exception')
    ->catchException('PEAR_Exception');
    // ...
    ]]></ac:plain-text-body></ac:macro>

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

    <p>if "mymethod" throws everything else, validate class don't catch it</p>

    1. Jun 12, 2009

      <p>I'm not sure if such a feature is even allowed.</p>

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

      <p>A validator returning exceptions is not good.</p>

  4. Jul 14, 2009

    <ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Framework Approval</ac:parameter><ac:rich-text-body>
    <p>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.</p></ac:rich-text-body></ac:macro>

  5. Jul 15, 2009

    <p>Can this validator check if a callback is valid ?</p>

    <p>e.g.</p>
    <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
    $callbackValidator = new Zend_Validate_Callback(/* empty to check only if a callback is valid */);
    $callbackValidator->isValid(array('MyClass', 'myStaticClassMethod'));
    $callbackValidator->isValid('MyClass::myStaticClassMethod');
    $callbackValidator->isValid(array($myObj, 'myObjMethod'));
    $callbackValidator->isValid('myFunction');

    $func = createfunction(...);
    $callbackValidator->isValid($func);

    $func = function () {}; // PHP 5.3
    $callbackValidator->isValid($func);
    ]]></ac:plain-text-body></ac:macro>

    1. Jul 16, 2009

      <p>Please read the comments and answer your question yourself.</p>

      1. Jul 16, 2009

        <p>Hi Thomas</p>

        <p>Then this callback validator isn't usable to check if a value is callable.<br />
        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.</p>

        <p>Greats</p>

        1. Jul 16, 2009

          <p>Marc,</p>

          <p>this proposal has been under public review for over 3 months.<br />
          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 ?</p>

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

          1. Jul 16, 2009

            <p>Hi Thomas</p>

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

            <p>The current version is only working as a wrapper for own functions.</p>

            <p>Greats</p>

            1. Sep 15, 2009

              <p>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.</p>

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

              1. Sep 15, 2009

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

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