auraphp/Aura.Filter

Alternative approach without factory

Closed this issue · 2 comments

Hi all,

I would like to discuss if anyone like this idea.

Currently the way of creating the Filter is via a FilterFactory and call the newSubjectFilter .

What I feel is we could improve the usage with something like

$filter = new Aura\Filter\SubjectFilter();

and in the class it can automatically add the dependencies if not passed.

class SubjectFilter
{
    public function __construct(
        ValidateSpec $validate_spec = null,
        SanitizeSpec $sanitize_spec = null,
        FailureCollection $failures = null
    ) {
        $this->validate_spec = $validate_spec ?: new ValidateSpec(new ValidateLocator());
        $this->sanitize_spec = $sanitize_spec ?: new SanitizeSpec(new SanitizeLocator());
        $this->proto_failures = $failures ?: new FailureCollection();
        $this->init();
    }
}

This helps to use Di if they are using it and if not passing their own or alternatively without anything if there is no other custom rule dependency.

I can make a PR if the idea seems good.

Thank you.

Same applies for ValueFilter

No, we keep object creation separate from object use.