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_Filter static usage Component Proposal

Proposed Component Name Zend_Filter static usage
Developer Notes static usage
Proposers Bill Karwin
Darby Felton
Revision 1.1 - 12 April 2007: initial writeup. (wiki revision: 7)

Table of Contents

  1. Overview
  2. References
  3. Requirements
  4. Dependencies on Other Framework Components
  5. Theory of Operation
  6. Milestones / Tasks
  7. Class Index
  8. Use Cases
  9. Skeletons
  10. Testing Strategy

1. Overview

This is a proposed solution for a convenient static method to allow Zend_Filter and Zend_Validate to work in an ad-hoc fashion.

This proposal is intended to supplement, not to replace the current object-oriented usage of Zend_Filter and Zend_Validate. You would still create instances of classes that implement Zend_Filter_Interface and Zend_Validate_Interface and use them as objects, call their isValid() and filter() methods, etc.

2. References

  • tbd

3. Component Requirements, Constraints, and Acceptance Criteria

  • This component will create an static interface to filtering and validating.
  • This component will load, instantiate, and invoke the Filter or Validate objects.
  • This component will support user-defined Filter and Validate classes in namespaces other than Zend_Filter and Zend_Validate.

4. Dependencies on Other Framework Components

  • Zend_Filter_Interface
  • Zend_Filter_Exception
  • Zend_Validate_Interface
  • Zend_Validate_Exception
  • other concrete classes that implement Zend_Filter_Interface and Zend_Validate_Interface

5. Theory of Operation

The call() method in classes Zend_Filter and Zend_Validate provide a static interface to invoke a single class that implement Zend_Filter_Interface or Zend_Validate_Interface respectively in their default usage. The desired filter or validator is specified by the class basename.

In the example above, 'filtername' is transformed to 'Zend_Filter_Filtername' and an instance is created. Then its filter() method is called on the $oldValue provided and the value returned.

If no such filter class can be found, an exception is thrown.

Some filters take arguments in their constructor. Pass these arguments as an array in the third argument to the call() method.

You can make the call() method search for classes in other namespaces than Zend_Filter and Zend_Validate, by passing a string or array as the fourth argument. User-specified namespaces are searched before Zend_Filter or Zend_Validate namespaces.

If the filter or validator takes no arguments, you must pass an empty array. A null or false is interpreted as an argument with that value to pass to the constructors.

6. Milestones / Tasks

  • Milestone 1: Post prototype design, gather community feedback
  • Milestone 2: Working prototype checked into the incubator supporting use cases
  • Milestone 3: Unit tests exist, work, and are checked into SVN.
  • Milestone 4: Write documentation.

If a milestone is already done, begin the description with "[DONE]", like this:

  • Milestone #: [DONE] Unit tests ...

7. Class Index

  • Zend_Filter
  • Zend_Validate

8. Use Cases


Apply a single Filter to a single value.


Apply a single Validator to a single value.


Use a user-defined validate class in a different namespace.

9. Class Skeletons


The following method is added to the Zend_Filter class. The existing methods of that class are not changed.


The following method is added to the Zend_Validate class. The existing methods of that class are not changed.

10. Testing Strategy

To be written.



Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Apr 20, 2007

    <p>Perhaps <code>filter()</code> and <code>validate()</code> would be better than <code>call()</code>.</p>

    1. Apr 21, 2007

      <p>I was thinking call() was a bit bland as well.</p>

      <p>I thought of <code>is()</code> for the validator. Then you could kind of "read" the line:</p>
      <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
      // Is value between 1 and 12?
      Zend_Validate::is($value 'Between', array(1,12));

      <p>Using a function called <code>validate()</code> would also have this characteristic of being roughly readable, but I didn't like putting the word 'validate' twice in a row:</p>
      <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
      Zend_Validate::validate($value 'Between', array(1,12));

      <p>However, for filter I didn't have a great idea for filtering. The best possibility I thought of was <code>get()</code>? </p>
      <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
      Zend_Filter::get($value, 'trim');
      <p>This is not readable in the same way as <code>Zend_Validate::is()</code> but <code>get()</code> is still nice and short, and perhaps better than <code>call()</code>.</p>

      1. Apr 22, 2007

        <p>Here's my vote(s):-</p>

        <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
        Zend_Filter::apply($value, 'trim');
        Zend_Filter::clean($value, 'trim');

        <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
        if (Zend_Validate::check($value, 'Between', array(1,12)) { ...
        if (Zend_Validate::test($value, 'Between', array(1,12)) { ...
        if (Zend_Validate::assert($value, 'Between', array(1,12)) { ...

  2. Apr 30, 2007

    <p>This is a really good idea to cut down verbose code. I would favour real language names such as:</p>
    <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
    Zend_Validate::is($value, 'Between', array(1,12));
    <p>Which sounds like "is $value between 1 and 12".</p>

    <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
    Zend_Validate::clean($value, 'HtmlEntities');
    <p>Which sounds like "clean $value with htmlentities".</p>

    <p>I have to say while I see the point of Zend_Validate with its more complex checks, Zend_Filter seems a little simplistic at times and I am tempted to just use simple htmlentities() functions for single calls.</p>

    <p>I can, however, see the benefit for repeated filters that may chain two or more filters. I guess different methods of use should please most people. I hope this is the Zend_Filter work Bill mentioned may be included in the next code freeze.</p>

    <p>My final comment would be can we please include a list of all filters and validations available in the manual. It's a little pain to have to search the API docs just to see what filters are available.</p>

  3. May 25, 2007

    <ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Comment</ac:parameter><ac:rich-text-body>
    <p>This proposal is approved for development.</p>