Re: HTML_QuickForm2_Rule_Callback: inverting callback rule results
| From: | Alexey Borzov | Date: | Thu, 13 May 2010 06:12:52 +0000 |
| Subject: | Re: HTML_QuickForm2_Rule_Callback: inverting callback rule results | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-30529@lists.php.net to get a copy of this message | ||
Hi Christian,
On 08.05.2010 11:53, Christian Weiske wrote:
OK, committed NotCallback and NotRegex rules, for some reason these commits didn't show in pear-cvs. I've never seen the need for MinFileSize rule, so didn't bother with this yet. Anyway, a better approach here will be to create a generic FileSize rule based on Length, rather than an inversion of MaxFileSize.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 anarray 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.