Code Monkey home page Code Monkey logo

Comments (23)

pmjones avatar pmjones commented on June 15, 2024

Good call. They'd need to be replaced in the FilterFactory and in the Config as wel.

from aura.filter.

brandonsavage avatar brandonsavage commented on June 15, 2024

Now, the issue comes if the user defines custom filters/validators, but we can solve that by creating a class of constants and the user can extend it. Let's discuss it next week in the channel.

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

I've tried this out and I just don't like the way it looks/feels when writing the rules.

use Aura\Filter\Rule\Rule;

$filter->validate('field')->is(Rule::STRLEN_BETWEEN, 6, 10);
// vs
$filter->validate('field')->is('strlenBetween', 6, 10);

I reserve the right to change my mind later.

from aura.filter.

koriym avatar koriym commented on June 15, 2024

Already closed, But I would like to drop my +1 for this proposal by @brandonsavage.
It helps autocomplete typing.

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

All right, then, that's two opinions to one. Let me see what I can do. :-)

from aura.filter.

brandonsavage avatar brandonsavage commented on June 15, 2024

Paul, feel free to show me what you've got so far and maybe I can help.

On Tue, Jul 7, 2015 at 8:50 AM, Paul M. Jones [email protected]
wrote:

Reopened #61 #61.


Reply to this email directly or view it on GitHub
#61 (comment).

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

Take a look at the newest 2.x work (released yesterday).

from aura.filter.

brandonsavage avatar brandonsavage commented on June 15, 2024

I meant did you already have an example of attempting constants?

On Tue, Jul 7, 2015 at 8:54 AM, Paul M. Jones [email protected]
wrote:

Take a look at the newest 2.x work (released yesterday).


Reply to this email directly or view it on GitHub
#61 (comment).

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

Ah! Just re-added the class of constants I tried out earlier, in a new branch : https://github.com/auraphp/Aura.Filter/tree/constants

from aura.filter.

harikt avatar harikt commented on June 15, 2024

Is there any issues if we keep both constants and string values ?

So the users can use what they need.

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

Is there any issues if we keep both constants and string values ?

Since the constants are strings, they end up being the same thing, so yes.

from aura.filter.

koriym avatar koriym commented on June 15, 2024

@pmjones @brandonsavage nice ! thanks.

from aura.filter.

brandonsavage avatar brandonsavage commented on June 15, 2024

@pmjones, what about that organization structure do you dislike?

On Tue, Jul 7, 2015 at 1:08 PM, Akihito Koriyama [email protected]
wrote:

@pmjones https://github.com/pmjones @brandonsavage
https://github.com/brandonsavage nice ! thanks.


Reply to this email directly or view it on GitHub
#61 (comment).

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

It's the difference between this ...

use Aura\Filter\Filter;
use Aura\Filter\FilterFactory;

$filter_factory = new FilterFactory();
$filter = $filter_factory->newSubjectFilter();

$filter->validate('password')->is(Filter::EQUAL_TO_FIELD, 'password_confirm');

... and this:

use Aura\Filter\FilterFactory;

$filter_factory = new FilterFactory();
$filter = $filter_factory->newSubjectFilter();

$filter->validate('password')->is('equalToField', 'password_confirm');

Further, when writing custom rules, one now needs to extend Filter as well, to incorporate a new constant, or mix constants with literal strings. First, adding the constant somewhere meaningful:

use Aura\Filter\Filter;

class MyFilter extends Filter
{
    const HEX = 'hex';
}

Then create the custom rules per the examples, then add them to the factories with the constant:

use MyFilter;
use Aura\Filter\FilterFactory;

$validate_factories = array(
    MyFilter::HEX => function () { return new Vendor\Package\Filter\Rule\Validate\ValidateHex(); },
);

$sanitize_factories = array(
    MyFilter::HEX => function () { return new Vendor\Package\Filter\Rule\Sanitize\SanitizeHex(); },
);

$filter_factory = new FilterFactory(
    $validate_factories,
    $sanitize_factories
);

$filter->validate('color')->is(MyFilter::HEX, 6);

In all, daily use just seems easier to go with string literals than constants. It's one less thing to worry about.

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

Overall I just don't like this approach. Do you still think it's a big deal?

from aura.filter.

koriym avatar koriym commented on June 15, 2024

when writing custom rules, one now needs to extend Filter as well, to incorporate a new constant, or mix constants with literal strings
...
In all, daily use just seems easier to go with string literals than constants. It's one less thing to worry about.

@pmjones I understand. The coding become more vary as you shown. Although I still prefer constants, The original method seems more Aura-way.

from aura.filter.

mivanov93 avatar mivanov93 commented on June 15, 2024

The constants idea seems fine. Considering this:

use MyFilter;
use Aura\Filter\FilterFactory;

$validate_factories = array(
    MyFilter::HEX => function () { return new Vendor\Package\Filter\Rule\Validate\ValidateHex(); },
);

$sanitize_factories = array(
    MyFilter::HEX => function () { return new Vendor\Package\Filter\Rule\Sanitize\SanitizeHex(); },
);

$filter_factory = new FilterFactory(
    $validate_factories,
    $sanitize_factories
);

$filter->validate('color')->is(MyFilter::HEX, 6);

Seems that we need the additional MyFilter class anyway, but otherwise we'd still have to:

use Aura\Filter\FilterFactory;

$validate_factories = array(
    'hex'=> function () { return new Vendor\Package\Filter\Rule\Validate\ValidateHex(); },
);

$sanitize_factories = array(
    'hex' => function () { return new Vendor\Package\Filter\Rule\Sanitize\SanitizeHex(); },
);

$filter_factory = new FilterFactory(
    $validate_factories,
    $sanitize_factories
);

and

$filter->validate('color')->is(MyFilter::HEX, 6);

vs

$filter->validate('color')->is('hex', 6);

So I see no savings except for MyFilter::HEX vs 'hex', but we could map MyFilter as something shorter :), like F, and then since it has a namespace we can get out of collisions and still preserve the meaning. SInce we will do something like use ....\MyFilter as F;

Also if we need custom filters, we might as well name them and make a class for them.
It's harder to make a mistake with a missing constant/also autocomplete.

Also what about the following(I haven't tested but it should be fine I think):

use Aura\Filter\Filter;

class MyFilter extends Filter
{
    const HEX = 'hex';
    public static $validate=array(self::HEX => function() { return new ....; });
    public static $sanitize=array(self::HEX => function() { return new ....; });
}


use MyFilter;
use Aura\Filter\FilterFactory;

$filter_factory = new FilterFactory(
    MyFilter::validate,
    MyFilter::sanitize
);
$filter->validate('color')->is(MyFilter::HEX, 6);

so we use the additional class to statically create our validation factories.

from aura.filter.

mivanov93 avatar mivanov93 commented on June 15, 2024

Thoughts, anyone?

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

I continue to not-like it.

from aura.filter.

brandonsavage avatar brandonsavage commented on June 15, 2024

I don't like it as much as I thought I would either.

On Thu, Jul 30, 2015 at 4:14 PM, Paul M. Jones [email protected]
wrote:

I continue to not-like it.


Reply to this email directly or view it on GitHub
#61 (comment).

from aura.filter.

mivanov93 avatar mivanov93 commented on June 15, 2024

What negative points are there to it? Can you elaborate? IMHO seems like a small addition that won't increase complexity and will add very minimal overhead, while saving time and guarding from errors(autocomplete).

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

It seems like that, in theory, but actual use of it on a regular basis is ... not compelling.

from aura.filter.

pmjones avatar pmjones commented on June 15, 2024

While this sounds nice in theory, in practice it turns out to be cumbersome. Even the original submitter is no longer convinced it's a good idea. Closing this until further practice shows otherwise.

from aura.filter.

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.