| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Jose\Component\Checker; |
| 6 |
|
| 7 |
use InvalidArgumentException; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class ClaimCheckerManagerFactory |
| 13 |
{ |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
private array $checkers = []; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public function create(array $aliases): ClaimCheckerManager |
| 26 |
{ |
| 27 |
$checkers = []; |
| 28 |
foreach ($aliases as $alias) { |
| 29 |
if (! isset($this->checkers[$alias])) { |
| 30 |
throw new InvalidArgumentException(sprintf( |
| 31 |
'The claim checker with the alias "%s" is not supported.', |
| 32 |
$alias |
| 33 |
)); |
| 34 |
} |
| 35 |
$checkers[] = $this->checkers[$alias]; |
| 36 |
} |
| 37 |
|
| 38 |
return new ClaimCheckerManager($checkers); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public function add(string $alias, ClaimChecker $checker): void |
| 45 |
{ |
| 46 |
$this->checkers[$alias] = $checker; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public function aliases(): array |
| 55 |
{ |
| 56 |
return array_keys($this->checkers); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public function all(): array |
| 65 |
{ |
| 66 |
return $this->checkers; |
| 67 |
} |
| 68 |
} |