Re: HTML_QuickForm2_Rule_Callback: inverting callback rule results
| From: | Christian Weiske | Date: | Sat, 08 May 2010 07:53:18 +0000 |
| Subject: | Re: HTML_QuickForm2_Rule_Callback: inverting callback rule results | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-30525@lists.php.net to get a copy of this message | ||
Hi Alexey,
> > You are correct. Anyhow any of those are not easy to grasp.
> > I solved the problem for me by registering an own "icallback" rule
> > [...]
> > Do you feel that the use case is too off-world, or are you accepting
> > patches for that?
>
> I thought about this a bit and it seems to me that 'notcallback' and
> probably 'notregex' rules may indeed be useful.
>
> Maybe it even makes sense to somehow add generic not_() alongside
> and_() and or_()? Can't come up with a good API, though.
>
> $user->addRule('callback', 'Username, etc.', array($userservice,
> 'existsUser')) ->not_();
not_() in this case would set some internal variable which causes the
rule to invert its value?
If one did
> $element->not_($element->addRule(..))
, not() would return an inversion-rule object that encapsulates the
given rule object - this is the second possibility, but it looks ugly
and is more chars to type.
Let's look at the rules:
+ Callback.php
- inversion makes sense
- Compare.php
- already has comparison operator, does not need inversion
- Each.php
- Is a semi-rule only that relies on other rules, no inversion needed
- Empty.php
- Already has Nonempty, no inversion needed
- Length.php
- has min and max settings, no inversion needed
+ MaxFileSize.php
- inversion makes only sense if one wants to have a minimum file size
- MimeType.php
- inversion makes no sense here, except when wanting to exclude an
array of mime types
- Nonempty.php
- Inversion to Empty.php
+ Regex.php
- Inversion makes sense
- Required.php
- Inversion is totally useless here.
So we have 3 rules here for which inversion makes sense, and only 2
often-needed ones. I think it's the easier/better way to add the
respective inverted rules instead of adding new methods to the API.
--
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