1 | <?php |
||
31 | class Cargo |
||
32 | { |
||
33 | /** |
||
34 | * Unique Identifier |
||
35 | * |
||
36 | * @var TrackingId |
||
37 | */ |
||
38 | private $trackingId; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $origin; |
||
44 | |||
45 | /** |
||
46 | * |
||
47 | * @var RouteSpecification |
||
48 | */ |
||
49 | private $routeSpecification; |
||
50 | |||
51 | /** |
||
52 | * @var Itinerary |
||
53 | */ |
||
54 | private $itinerary; |
||
55 | |||
56 | /** |
||
57 | * Construct |
||
58 | * |
||
59 | * @param TrackingId $aTrackingId |
||
60 | * @param RouteSpecification $aRouteSpecification |
||
61 | */ |
||
62 | public function __construct(TrackingId $aTrackingId, RouteSpecification $aRouteSpecification) |
||
63 | { |
||
64 | $this->trackingId = $aTrackingId; |
||
65 | |||
66 | //Construct is only called when the Cargo is initially created. |
||
67 | //Doctrine do not call __construct when it recreates a persisted entity. |
||
68 | //Therefor we can assign the origin here. |
||
69 | //It will be always the same for that specific Cargo even if the RouteSpecification changes. |
||
70 | $this->origin = $aRouteSpecification->origin(); |
||
71 | |||
72 | $this->routeSpecification = $aRouteSpecification; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return TrackingId Unique Identifier of this Cargo |
||
77 | */ |
||
78 | public function trackingId(): TrackingId |
||
82 | |||
83 | /** |
||
84 | * @return string Origin of this Cargo |
||
85 | */ |
||
86 | public function origin(): string |
||
90 | |||
91 | /** |
||
92 | * @return RouteSpecification |
||
93 | */ |
||
94 | public function routeSpecification(): RouteSpecification |
||
98 | |||
99 | /** |
||
100 | * Specifies a new route for this cargo. |
||
101 | * |
||
102 | * @param RouteSpecification $aRouteSpecification |
||
103 | */ |
||
104 | public function specifyNewRoute(RouteSpecification $aRouteSpecification) |
||
108 | |||
109 | /** |
||
110 | * @return Itinerary Never null |
||
111 | */ |
||
112 | public function itinerary(): Itinerary |
||
113 | { |
||
114 | if (is_null($this->itinerary)) { |
||
115 | return new Itinerary(array()); |
||
116 | } else { |
||
117 | return $this->itinerary; |
||
118 | } |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Attach a new itinerary to this cargo. |
||
123 | * |
||
124 | * @param Itinerary $anItinerary |
||
125 | */ |
||
126 | public function assignToRoute(Itinerary $anItinerary) |
||
130 | |||
131 | /** |
||
132 | * @param Cargo $other |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function sameIdentityAs(Cargo $other): bool |
||
139 | } |
||
140 |