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

42 lines
1021 B
PHP

<?php
namespace com\fwdekker\deathnotifier\validator;
/**
* A set of {@see Rule Rules} to apply to an array of inputs.
*/
class RuleSet
{
/**
* @var array<string, array<Rule>> the rules to apply to the inputs
*/
private readonly array $rule_set;
/**
* Constructs a new `RuleSet`.
*
* @param array<string, array<Rule>> $rules the rules to apply to the inputs
*/
public function __construct(array $rules)
{
$this->rule_set = $rules;
}
/**
* Verifies that the input is of the specific length.
*
* @param array<int|string, mixed> $inputs the list of inputs to validate
* @return void if the inputs satisfy the rules of this rule set
* @throws InvalidInputException if any input does not satisfy any rule of this rule set
*/
public function check(array $inputs): void
{
foreach ($this->rule_set as $key => $rules)
foreach ($rules as $rule)
$rule->check($inputs, $key);
}
}