Debian Codegraph @

lib/3rdParty/composer/facile-it/php-openid-client/src/AuthMethod/AuthMethodFactory.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Facile\OpenIDClient\AuthMethod;
6
7 use Facile\OpenIDClient\Exception\InvalidArgumentException;
8 use Override;
9
10 final class AuthMethodFactory implements AuthMethodFactoryInterface
11 {
12 /** @var AuthMethodInterface[] */
13 private array $methods = [];
14
15 /**
16 * AuthMethodFactory constructor.
17 *
18 * @param AuthMethodInterface[] $methods
19 */
20 public function __construct(array $methods = [])
21 {
22 foreach ($methods as $method) {
23 $this->add($method);
24 }
25 }
26
27 public function add(AuthMethodInterface $authMethod): void
28 {
29 $this->methods[$authMethod->getSupportedMethod()] = $authMethod;
30 }
31
32 /**
33 * @psalm-api
34 *
35 * @return AuthMethodInterface[]
36 */
37 public function all(): array
38 {
39 return $this->methods;
40 }
41
42 #[Override]
43 public function create(string $authMethod): AuthMethodInterface
44 {
45 $method = $this->methods[$authMethod] ?? null;
46
47 if (null === $method) {
48 throw new InvalidArgumentException('Unsupported auth method "' . $authMethod . '"');
49 }
50
51 return $method;
52 }
53 }