-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rules.php
47 lines (38 loc) · 973 Bytes
/
Rules.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/*
* This file is part of fab2s/dt0.
* (c) Fabrice de Stefanis / https://github.com/fab2s/dt0
* This source file is licensed under the MIT license which you will
* find in the LICENSE file or at https://opensource.org/licenses/MIT
*/
namespace fab2s\Dt0\Attribute;
use Attribute;
#[Attribute(Attribute::TARGET_CLASS)]
class Rules
{
/**
* @var array<string, Rule>
*/
protected array $rules = [];
public function __construct(
Rule ...$rules,
) {
foreach ($rules as $name => $rule) {
if (is_int($name)) {
if (! $rule->propName) {
continue;
}
$name = $rule->propName;
}
$this->rules[$name] = $rule;
}
}
public function hasRule($name): bool
{
return isset($this->rules[$name]);
}
public function getRule($name): ?Rule
{
return $this->rules[$name] ?? null;
}
}