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

28 lines
788 B
PHP

<?php
namespace com\fwdekker\deathnotifier\validator;
/**
* Validates that the input is set.
*/
class IsSetRule extends Rule
{
/**
* Validates that the input is set.
*
* @param array<int|string, mixed> $inputs the list of inputs in which the value at {@see $key} should be checked
* @param string $key the key in {@see $inputs} of the input to check
* @return void if the checked input is set
* @throws InvalidInputException if the checked input is not set
*/
public function check(array $inputs, string $key): void
{
if (!isset($inputs[$key]))
throw new InvalidInputException(
$this->override_message ?? "Field '" . htmlentities($key) . "' must be set.",
$key
);
}
}