1 | <?php |
||
26 | final class RaLocationList implements IteratorAggregate |
||
27 | { |
||
28 | /** |
||
29 | * @var RaLocation[] |
||
30 | */ |
||
31 | private $raLocations = []; |
||
32 | |||
33 | public function __construct(array $raLocations) |
||
39 | |||
40 | /** |
||
41 | * @param RaLocationId $raLocationId |
||
42 | * @return bool |
||
43 | */ |
||
44 | public function containsWithId(RaLocationId $raLocationId) |
||
45 | { |
||
46 | foreach ($this->raLocations as $raLocation) { |
||
47 | if ($raLocation->hasRaLocationId($raLocationId)) { |
||
48 | return true; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | return false; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param RaLocation $raLocation |
||
57 | */ |
||
58 | public function add(RaLocation $raLocation) |
||
69 | |||
70 | /** |
||
71 | * @param RaLocationId $raLocationId |
||
72 | */ |
||
73 | public function removeWithId(RaLocationId $raLocationId) |
||
74 | { |
||
75 | foreach ($this->raLocations as $key => $raLocation) { |
||
76 | if ($raLocation->hasRaLocationId($raLocationId)) { |
||
77 | unset($this->raLocations[$key]); |
||
78 | $this->raLocations = array_values($this->raLocations); |
||
79 | |||
80 | return; |
||
81 | } |
||
82 | } |
||
83 | |||
84 | throw new LogicException(sprintf( |
||
85 | 'Cannot remove RaLocation with id "%s" from RaLocationList: it is not present', |
||
86 | $raLocationId |
||
87 | )); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param RaLocationId $raLocationId |
||
92 | * @return RaLocation |
||
93 | */ |
||
94 | public function getById(RaLocationId $raLocationId) |
||
95 | { |
||
96 | foreach ($this->raLocations as $raLocation) { |
||
97 | if ($raLocation->hasRaLocationId($raLocationId)) { |
||
98 | return $raLocation; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | throw new LogicException(sprintf( |
||
103 | 'Cannot get RaLocation by id "%s" from RaLocationList: RaLocationId not found', |
||
104 | $raLocationId |
||
105 | )); |
||
106 | } |
||
107 | |||
108 | public function getIterator() |
||
112 | } |
||
113 |