Code Monkey home page Code Monkey logo

Comments (16)

pmjones avatar pmjones commented on June 2, 2024

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.

harikt avatar harikt commented on June 2, 2024

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.

pmjones avatar pmjones commented on June 2, 2024

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.

harikt avatar harikt commented on June 2, 2024

ok.

from aura.input.

pmjones avatar pmjones commented on June 2, 2024

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.

harikt avatar harikt commented on June 2, 2024

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.

pmjones avatar pmjones commented on June 2, 2024

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.

pmjones avatar pmjones commented on June 2, 2024

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.

harikt avatar harikt commented on June 2, 2024

:-) .

lol did I bribed you ;-)

from aura.input.

pmjones avatar pmjones commented on June 2, 2024

"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.

harikt avatar harikt commented on June 2, 2024

oh my God.

I am sorry to hear I irritated you. Not in the future :-) .

from aura.input.

pmjones avatar pmjones commented on June 2, 2024

Not at all, sir; it was a joke. You help keep me on the right path. :-)

from aura.input.

harikt avatar harikt commented on June 2, 2024

:-)

from aura.input.

pmjones avatar pmjones commented on June 2, 2024

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.

harikt avatar harikt commented on June 2, 2024

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.

harikt avatar harikt commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.