Preconditions

At the heart of the Evaluator are the preconditions that can be evaluated, when a request contain such. They are responsible for invoking appropriate actions, if applicable, whenever they pass or fail.

Supported Preconditions

Unless otherwise specified, the following preconditions are enabled by default in the Evaluator.

RFC 9110

Extensions

Disable Extensions

If you do not wish to allow any other kind of preconditions evaluation than those defined by RFC 9110, then you can invoke the useRfc9110Preconditions() method.

$evaluator->useRfc9110Preconditions();

Specify Preconditions

Order of precedence

All preconditions are evaluated in the order that they are given. This means that the default are evaluated in accordance with RFC 9110's order of precedenceopen in new window.

To specify what preconditions can be evaluated, set the $preconditions argument in the make() method. Or, use the setPreconditions() method.

// When creating a new instance...
$evaluator = Evaluator::make(
    request: $request,
    preconditions: [
        MyCustomPreconditionA::class,
        new OtherCustomPrecontion()
    ],
);

// Or, when after instance has been instantiated
$evaluator->setPreconditions([
    MyCustomPreconditionA::class,
    new OtherCustomPrecontion()
]);

Alternatively, if you wish to add a custom precondition to be evaluated after those that are already set (e.g. the default preconditions), then use the addPrecondition() method. Just like when set custom preconditions, the method accepts a string class path or precondition instance as argument.

$evaluator->addPrecondition(new MyCustomPrecondition());

Custom Preconditions

See extensions for more information.