ZF-212: Some extra methods for Zend_Filter

Description


    /**
     * Test whether the length of a string is greater than a certain amount
     *
     * @param string $value
     * @param integer $length
     * @return bool
     */
    public static function testLengthGreaterThan($value, $length)
    {
        return strlen($value) > $length;
    }
    /**
     * Test whether the length of a string is less than a certain amount
     *
     * @param string $value
     * @param integer $length
     * @return bool
     */
    public static function testLengthLessThan($value, $length)
    {
        return strlen($value) < $length;
    }
    /**
     * Test whether the key is empty. 
     * 
     * @param string $value
     * @return bool
     */
    public function testEmpty($value)
    {
        return empty($value);
    }

Comments

I think these are a good suggestion..

I will get a patch organised.

Great thank you.

Just realised the testLengthLessThan() and testLengthGreaterThan() functions should have an $inclusive argument to conform with existing testGreaterThan() and testLessThan()

What is the status of this patch? Do you think that it will make it into the 0.1.6 release?

This is a patch to have the filter object has a testEmpty in the Zend_Filter_Input Class and a isEmpty function in the Zend_Filter Class.

Ok so i am sorry about my first patch submitted but it doesnt work correctly. after doing more testing i found a quick bug in it that i am currently fixing. I will post a new one once i'm sure it works across the board. I didnt see a way to delete or mark a file a out dated.

Changing fix version to 0.9.0.

In my opinion the testEmpty() and isEmpty() methods are completeley unnecessary. In fact it's a oneliner.

I don't see them as being unnecessary as right now to test is something is empty you would have to set it to a variable then test the variable to see if it's empty, which makes it two lines not one.

This code will not work as it generates a parse error.


if(empty($name = $filterList->getRaw('an_name'))) {

I see a value in having a testEmpty function as then you can easily test to see if it's empty in one line instead of setting it to a variable and then testing that variable.

{{Zend_Filter}} no longer uses static methods for filtering. Instead, {{Zend_Validate_StringLength}} may be used for the string length testing purposes.

If the need remains for an "isEmpty" validation class, please feel free to formalize the suggestion by writing a proposal that covers the use cases and solution details.