43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace com\fwdekker\deathnotifier\validator;
|
|
|
|
use com\fwdekker\deathnotifier\Response;
|
|
|
|
|
|
/**
|
|
* A rule/constraint/assertion that should hold over an input.
|
|
*/
|
|
abstract class Rule
|
|
{
|
|
/**
|
|
* @var string|null The message to return if the rule does not apply to some input. If `null`, the rule
|
|
* implementation can choose an appropriate message.
|
|
*/
|
|
public ?string $override_message;
|
|
|
|
|
|
/**
|
|
* Instantiates a new rule.
|
|
*
|
|
* @param string|null $override_message the message to return if the rule does not apply to some input. If `null`,
|
|
* the rule implementation can choose an appropriate message
|
|
*/
|
|
public function __construct(?string $override_message = null)
|
|
{
|
|
$this->override_message = $override_message;
|
|
}
|
|
|
|
|
|
/**
|
|
* Checks whether the rule holds for `$inputs[$key]`.
|
|
*
|
|
* Implementations should never assume that the `$inputs[$key]` is set.
|
|
*
|
|
* @param array<string, mixed> $inputs the list of inputs in which the value at `key` should be checked
|
|
* @param string $key the key in `inputs` of the input to check
|
|
* @return Response|null `null` if the rule holds, or an unsatisfied `Response` otherwise
|
|
*/
|
|
public abstract function check(array $inputs, string $key): ?Response;
|
|
}
|