ZF-8156: Zend_Validate_Identical : __construct method doesn't take an array

Description

Hi,

Imho, the component should take an array too, in its __construct method to allow the use with array configured elements. With the last SVN version of the file, it doesn't work anymore for me.

Here's my code :

$this->addElement( 'checkbox', 'confirm', array(
    'label' => '#__label::confirm_your_will_to_remove_this__#',
    'validators' => array(
        array(
            'validator' => 'Identical',
            'options' => array(
                'token' => '1',
                'messages' => array(
                    'notSame' => '#__error::you_have_to_confirm_your_will__#'
                )
            )
        )
    ),
    'required' => true
) );

And when I Zend_Debug::dump( ...->getToken() ), I get this :

array(1) {
  ["token"] => string(1) "1"
}

when it should be :

```

I don't figure out why it does this like that now, with the 1.9.4, everything's ok.

Comments

Maybe something like this ?

public function __construct($token = null)
{
    if ($token instanceof Zend_Config) {
        $token = $token->toArray();
    }

    if ( is_array( $token ) ) {
        if (array_key_exists('token', $token)) {
            $token = $token['token'];
        } else {
            require_once 'Zend/Validate/Exception.php';
            throw new Zend_Validate_Exception("Missing option 'token'");
        }
    }

    if (null !== $token) {
        $this->setToken($token);
    }
}

Out of curiosity, what do you want to archive ? Comparing "1" with an object will not work... this will never return true.

Why do you expect that you must give array("token" => xxxx) as parameter ? It is no-where documented this way.

Sorry to say that, but it could not have worked since below 1.6. I did not check before this release.

The messages are stripped by Zend_Form. All remaining options are set as is to the validator.

This means you have set ``` as token.

When you would simply set '1' instead of array(xxx), then you would have the expected behaviour.

Note that the identical validator validates now "ANY" datastructure for identical-ness. Previously all inputs were converted to string. For Arrays this meant that you had "array" which produced wrong behaviour.

So you tell me that there's no way to customize the messages ? It sounds weird to me, because it was working like that for me without any problem.

Since months, I generated my forms by passing an array or a Zend_Config object containing all my options, including the custom messages. It stopped working when I updated Zend from the SVN this morning.

If I understand what you are saying, how do I write my array of options to specify my custom messages ?

See you.

Your issue was about "token" not being recognised as input for configuration.

It was not about customizing messages.

When your problem is that "messages" is not recognised as parameter within the validator, then you should use the correct notation. Because in this case Zend_Validate is not the problem, as you are using Zend_Form and it is Zend_Form which sets the messages on the validator.

My issue was about "token", yes, but as I didn't understand that it is Zend_Form which sets the messages on the validator, I tought it was an issue. I understand better now that Zend_Form does that messages setting stuff.

But in this case, why do you allow passing a Zend_Config object? I don't really understand why if the expected behaviour is to pass only the token (so one and ONLY ONE value), and why a Zend_Config object and not an array or not both. In this case, why bothering to check if this is a Zend_Config object?

See you.

Just because you don't understand features which are documented and available for other use cases does not mean that this features are useless.

Please note that the feature you are disapointed about is available only for 1.10 and above, and not for 1.9.5 as reported by you.

So what is your issue about ?

Hey, I'm not disapointed and I don't say this features is useless. It's not because I'm asking "why" that I think it's useless or wrong.

You answered my question above and so my issue wasn't an issue. End of the issue. Sorry bothering you with my questions, I didn't think I was so misplaced.

Bye.

Implemented with r18724. Rewrote manual.

Note that the origin of this issue is no issue as already mentioned. You need to set the options for Zend_Form properly to get translated messages.