Skip to content

Introduce the concept of filters #12

Description

@krixon

Filters allow the values represented by identifiers to be processed prior to specification evaluation. For example:

foo|upper is "ABC" // convert foo to uppercase before comparison.
foo|lower|trim is "abc" // trim whitespace, then convert foo to lowercase before comparison.

Filters are made available via the Comparison node by way of the Identifier node. When a filter applies to an Identifier node, it is present on the root identifier only and is considered to apply to the whole thing.

Specifications must be responsible for applying filters since they have the job of extracting a value for a given identifier. This should therefore be as simple as possible to minimise the burden:

public function isSatisfiedBy($value) : bool
{
    if (!$value instanceof User) {
        return false;
    }

    $value = $this->filters->apply($value->getUsername());

    // ...
}

There is no need to allow filters to apply to Literal nodes since they can be written in the required format in the first place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions