Comments (16)
Aura\Input\Filter is not intended as a final solution for filtering. It is the barest, most basic possible implementation of a minimal interface that allows filtering. Every added method means one more method that implementors need to add. As such, I'm not inclined to create an "addRule()" method.
from aura.input.
if something exists it should be good, else none is better :) . So I strongly feel to add :-) . What are the limitations you feel not adding it other than final solution for filtering ?
from aura.input.
The primary reason is that anyone who wants to implement it will need to add the additional method. For example, Aura.Filter (which had addSoftRule(), addHardRule(), and addStopRule() to begin with) added setRule() so that it could implement Aura\Input\Filter. There's no point in creating addRule() as well, when a closure can encapsulate as much logic as one wants.
from aura.input.
ok.
from aura.input.
Maybe the thing to do is replace "setRule()" with "addRule()", leave the signature the same, and thereby allow for multiple rules. I don't really like it, but it does address your concern about separate messages.
from aura.input.
You can keep the setRule
there itself. I have no concern about setRule
, but adding an addRule
will change the implementation of the value
method
<?php
public function addRule($field, $message, \Closure $closure)
{
$this->rules[$field][] = [$message, $closure];
}
/**
*
* Filter and Validate the data
*
* @param mixed $values The value
*
* @return bool
*
*/
public function values(&$values)
{
// reset the messages
$this->messages = [];
// go through each of the rules
foreach ($this->rules as $field => $rules) {
// A field can have more rules
foreach ($rules as $rule) {
// get the closure and message
list($message, $closure) = $rule;
// apply the closure to the data and get back the result
$passed = $closure($values[$field]);
// if the rule did not pass, retain a message for the field.
// note that it is in an array, so that other implementations
// can allow for multiple messages.
if (! $passed) {
$this->messages[$field][] = $message;
}
}
}
// if there are messages, one or more values failed
return $this->messages ? false : true;
}
from aura.input.
If there's an addRule() then there's no need for a setRule(); you can use addRule() once and get the same effect. As long as there's only one method to implement relating to rules.
from aura.input.
Yeah, the more I think about this, the more I think replacing setRule() with addRule(), and multiple rules, is the way to go. Thanks for bringing this up. :-)
from aura.input.
:-) .
lol did I bribed you ;-)
from aura.input.
"Bribe" means you gave me money (or other compensation) to change my mind. What you did was "nag" me; you will have a wife soon and learn what that means by experience. ;-)
from aura.input.
oh my God.
I am sorry to hear I irritated you. Not in the future :-) .
from aura.input.
Not at all, sir; it was a joke. You help keep me on the right path. :-)
from aura.input.
:-)
from aura.input.
I tried this out, and it just doesn't "feel" right when combined with Aura.Filter. The problem is this:
- setRule() sets one rule for the field, and sets one message for the field.
- addRule() adds a rule for the field (possibly one of many), and sets on message for the field, but if another rule gets added using addRule(), its message overrides the message from the previous addRule().
Of the two, I think using setRule() as it is causes less confusion and integrates better across the board.
Thanks for suggesting it, regardless.
from aura.input.
then you need to revert this commit I guess. The merge of issue #11 already has it . See https://github.com/auraphp/Aura.Input/pull/11/files#L1R38
from aura.input.
By the way I have not tried it to reply back, nor I don't think I will get some time to check. So if I see at some point I will reply 👍
from aura.input.
Related Issues (20)
- What about automatic id HOT 5
- GetItrator() throw NoSuchInput exception
- Packagist "dev-develop" refference is not updated. HOT 1
- FormFactory HOT 5
- There should be a way to set error messages for the field
- getValues HOT 2
- Need hasField HOT 4
- When there is post value for csrf token HOT 2
- Fieldsets and collections HOT 12
- Add an empty row to the collection HOT 6
- 1.1.1 missing the extra in composer.json HOT 1
- May be a isSuccess flag HOT 6
- Delete form and initial branch?
- Re: An addR HOT 1
- Regarding "Add an addRule" HOT 6
- Starting 3.x HOT 11
- [Bug] Form missed to filter for Collection and Fieldset HOT 1
- On integrating Filter and Input. Are we sure? HOT 6
- Why no setOptions on Fieldset? HOT 3
- What is the future of this project? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aura.input.