1 | <?php |
||
26 | final class RaLocationList implements IteratorAggregate |
||
27 | { |
||
28 | /** |
||
29 | * @var RaLocation[] |
||
30 | */ |
||
31 | private $raLocations = []; |
||
32 | |||
33 | public function __construct(array $raLocations) |
||
34 | { |
||
35 | foreach ($raLocations as $raLocation) { |
||
36 | $this->add($raLocation); |
||
37 | } |
||
38 | } |
||
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->hasId($raLocationId)) { |
||
48 | return true; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | return false; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param RaLocation $raLocation |
||
57 | */ |
||
58 | public function add(RaLocation $raLocation) |
||
59 | { |
||
60 | if ($this->containsWithId($raLocation->getId())) { |
||
61 | throw new LogicException(sprintf( |
||
62 | 'Cannot add RaLocation with id "%s" to RaLocationList: it is already present', |
||
63 | $raLocation->getId() |
||
64 | )); |
||
65 | } |
||
66 | |||
67 | $this->raLocations[] = $raLocation; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param RaLocationId $raLocationId |
||
72 | */ |
||
73 | public function removeWithId(RaLocationId $raLocationId) |
||
89 | |||
90 | /** |
||
91 | * @param RaLocationId $raLocationId |
||
92 | * @return RaLocation |
||
93 | */ |
||
94 | public function getById(RaLocationId $raLocationId) |
||
107 | |||
108 | public function getIterator() |
||
112 | } |
||
113 |