death-notifier/src/main/php/com/fwdekker/deathnotifier/validator/IsSetRule.php

27 lines
765 B
PHP

<?php
namespace com\fwdekker\deathnotifier\validator;
use com\fwdekker\deathnotifier\Response;
/**
* Requires the input to be set.
*/
class IsSetRule extends Rule
{
/**
* Checks whether the input 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 `isset($inputs[$key])`, or an unsatisfied `Response` otherwise
*/
public function check(array $inputs, string $key): ?Response
{
return !isset($inputs[$key])
? Response::unsatisfied($this->override_message ?? "Field '" . htmlentities($key) . "' required.", $key)
: null;
}
}