Re: HTML_QuickForm2_Rule_Callback: inverting callback rule results
| From: | Christian Weiske | Date: | Tue, 04 May 2010 17:10:50 +0000 |
| Subject: | Re: HTML_QuickForm2_Rule_Callback: inverting callback rule results | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-30507@lists.php.net to get a copy of this message | ||
Hello Alexey,
> > Of course I would prefer number 2, since adding a "'inverted' =>
> > true" option to the callback rule is much easier and faster than
> > defining an own function/adapting the API.
> >
> > What do you think about that?
>
> While it won't be difficult to add such a parameter, I don't see how
>
> $user->addRule('callback', 'Username already taken',
> array('callback' => array($userservice, 'existsUser'),
> 'inverted' => true));
>
> is better than
> $user->addRule('callback', 'Username already taken',
> array('callback' => create_function(
> '$v, $userservice',
> 'return !$userservice->existsUser($v);'), 'arguments' =>
> array($userservice));
>
> or even, in PHP 5.3
> $user->addRule('callback', 'Username already taken',
> function ($v) use ($userservice) {
> return !$userservice->existsUser($v);
> });
>
> For me the last example looks A LOT easier to understand.
You are correct. Anyhow any of those are not easy to grasp.
I solved the problem for me by registering an own "icallback" rule that
just inverts the result of the normal callback - resulting in the most
simple code possible.
> $user->addRule(
> 'icallback', 'Username already taken',
> array('callback' => array($userservice, 'existsUser'))
> );
Do you feel that the use case is too off-world, or are you accepting
patches for that?
--
Regards/Mit freundlichen Grüßen
Christian Weiske
-=≡ Geeking around in the name of science since 1982 ≡=-
Attachment: [application/pgp-signature] signature.asc
Attachment: [application/pgp-signature] signature.asc