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

Issue Type: Improvement Created: 2009-10-27T02:01:29.000+0000 Last Updated: 2009-10-28T00:56:28.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Karl Delandsheere (karl~ofthedead) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate

Related issues: Attachments:



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 :

<pre class="highlight">$this->addElement( 'checkbox', 'confirm', array(
    'label' => '#__label::confirm_your_will_to_remove_this__#',
    'validators' => 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 :

<pre class="highlight">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

Posted by Karl Delandsheere (karl~ofthedead) on 2009-10-27T02:44:54.000+0000

Maybe something like this ?

    <pre class="highlight">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) {



Posted by Thomas Weidner (thomas) on 2009-10-27T07:52:46.000+0000

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.



Posted by Thomas Weidner (thomas) on 2009-10-27T11:43:53.000+0000

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.



Posted by Karl Delandsheere (karl~ofthedead) on 2009-10-27T13:37:23.000+0000

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.



Posted by Thomas Weidner (thomas) on 2009-10-27T14:30:58.000+0000

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.



Posted by Karl Delandsheere (karl~ofthedead) on 2009-10-27T15:01:58.000+0000

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.



Posted by Thomas Weidner (thomas) on 2009-10-27T15:56:59.000+0000

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 ?



Posted by Karl Delandsheere (karl~ofthedead) on 2009-10-27T21:54:49.000+0000

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.




Posted by Thomas Weidner (thomas) on 2009-10-28T00:56:24.000+0000

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.



Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.