1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2023 SURFnet bv |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
|
|
|
|
20
|
|
|
|
21
|
|
|
namespace Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider; |
22
|
|
|
|
23
|
|
|
use Surfnet\SamlBundle\Metadata\MetadataFactory; |
24
|
|
|
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Exception\MetadataFactoryNotFoundException; |
25
|
|
|
|
26
|
|
|
class MetadataFactoryCollection |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
/** |
|
|
|
|
29
|
|
|
* @var array<string, MetadataFactory> |
30
|
|
|
*/ |
31
|
|
|
private array $metadataFactoryCollection = []; |
|
|
|
|
32
|
|
|
|
33
|
|
|
public function getByIdentifier(string $provider): MetadataFactory |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
if (!$this->has($provider)) { |
36
|
|
|
throw new MetadataFactoryNotFoundException( |
37
|
|
|
message: "The provider {$provider} does not exist in the collection" |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $this->metadataFactoryCollection[$provider]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
private function has(string $provider): bool |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
return array_key_exists($provider, $this->metadataFactoryCollection); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function add(string $provider, MetadataFactory $factory): void |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
if ($this->has($provider)) { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
$this->metadataFactoryCollection[$provider] = $factory; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|