1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2018 SURFnet bv |
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\Stepup\Identity\Entity; |
20
|
|
|
|
21
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionRole; |
22
|
|
|
use Surfnet\Stepup\Identity\Value\Institution; |
23
|
|
|
use \Surfnet\Stepup\Identity\Collection\InstitutionCollection as Institutions; |
24
|
|
|
|
25
|
|
|
final class InstitutionCollection |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var InstitutionRole[] |
29
|
|
|
*/ |
30
|
|
|
private $institutions = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param Institution $institution |
34
|
|
|
*/ |
35
|
|
|
public function set(Institution $institution) |
36
|
|
|
{ |
37
|
|
|
$this->institutions[(string)$institution] = $institution; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param Institutions $institutions |
42
|
|
|
*/ |
43
|
|
|
public function update(Institutions $institutions) |
44
|
|
|
{ |
45
|
|
|
foreach ($institutions as $institution) { |
46
|
|
|
$this->institutions[(string)$institutions] = $institution; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param Institution $institution |
52
|
|
|
* @return Institution |
|
|
|
|
53
|
|
|
*/ |
54
|
|
|
public function get(Institution $institution) |
55
|
|
|
{ |
56
|
|
|
return $this->institutions[(string)$institution]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Institution $institution |
61
|
|
|
* @return Institution |
|
|
|
|
62
|
|
|
*/ |
63
|
|
|
public function exists(Institution $institution) |
64
|
|
|
{ |
65
|
|
|
return array_key_exists((string)$institution, $this->institutions); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param Institution $institution |
70
|
|
|
*/ |
71
|
|
|
public function remove(Institution $institution) |
72
|
|
|
{ |
73
|
|
|
unset($this->institutions[(string)$institution]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return int |
78
|
|
|
*/ |
79
|
|
|
public function count() |
80
|
|
|
{ |
81
|
|
|
return count($this->institutions); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.