-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClaimCheckerManagerFactory.php
65 lines (56 loc) · 1.53 KB
/
ClaimCheckerManagerFactory.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Jose\Component\Checker;
use InvalidArgumentException;
class ClaimCheckerManagerFactory
{
/**
* @var ClaimChecker[]
*/
private array $checkers = [];
/**
* This method creates a Claim Checker Manager and populate it with the claim checkers found based on the alias. If
* the alias is not supported, an InvalidArgumentException is thrown.
*
* @param string[] $aliases
*/
public function create(array $aliases): ClaimCheckerManager
{
$checkers = [];
foreach ($aliases as $alias) {
if (! isset($this->checkers[$alias])) {
throw new InvalidArgumentException(sprintf(
'The claim checker with the alias "%s" is not supported.',
$alias
));
}
$checkers[] = $this->checkers[$alias];
}
return new ClaimCheckerManager($checkers);
}
/**
* This method adds a claim checker to this factory.
*/
public function add(string $alias, ClaimChecker $checker): void
{
$this->checkers[$alias] = $checker;
}
/**
* Returns all claim checker aliases supported by this factory.
*
* @return string[]
*/
public function aliases(): array
{
return array_keys($this->checkers);
}
/**
* Returns all claim checkers supported by this factory.
*
* @return ClaimChecker[]
*/
public function all(): array
{
return $this->checkers;
}
}