|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2020 SURFnet B.V. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Value; |
|
20
|
|
|
|
|
21
|
|
|
use ArrayIterator; |
|
22
|
|
|
use IteratorAggregate; |
|
23
|
|
|
use JsonSerializable; |
|
24
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Assert; |
|
25
|
|
|
|
|
26
|
|
|
class AttributeCollection implements IteratorAggregate, AttributeCollectionInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var Attribute[] |
|
30
|
|
|
*/ |
|
31
|
|
|
private $attributes = []; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct($attributes) |
|
34
|
|
|
{ |
|
35
|
|
|
Assert::isArray($attributes, 'The $attributes of an AttributeCollection must be an array value'); |
|
36
|
|
|
|
|
37
|
|
|
foreach ($attributes as $attributeName => $attributeValue) { |
|
38
|
|
|
$this->add(new Attribute($attributeName, $attributeValue)); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function add(Attribute $attribute) |
|
43
|
|
|
{ |
|
44
|
|
|
// Attributes are not |
|
45
|
|
|
$this->attributes[] = $attribute; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getIterator() |
|
49
|
|
|
{ |
|
50
|
|
|
return new ArrayIterator($this->attributes); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getAttributes() |
|
54
|
|
|
{ |
|
55
|
|
|
$output = []; |
|
56
|
|
|
foreach ($this->attributes as $attribute) { |
|
57
|
|
|
$output[$attribute->getName()] = $attribute; |
|
58
|
|
|
} |
|
59
|
|
|
return $output; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|