1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: davis |
5
|
|
|
* Date: 7/23/17 |
6
|
|
|
* Time: 3:04 AM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace DavisPeixoto\BlogCore\Entity; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Ramsey\Uuid\UuidInterface; |
13
|
|
|
use stdClass; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Trail |
17
|
|
|
* @package DavisPeixoto\Entity |
18
|
|
|
*/ |
19
|
|
|
class Trail extends stdClass |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var UuidInterface |
23
|
|
|
*/ |
24
|
|
|
private $trailId; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $name; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $description; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array|Post[] |
38
|
|
|
*/ |
39
|
|
|
private $posts; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Trail constructor. |
43
|
|
|
* @param UuidInterface $trailId |
44
|
|
|
* @param string $name |
45
|
|
|
* @param string $description |
46
|
|
|
* @param Post[] $posts |
47
|
|
|
*/ |
48
|
|
|
public function __construct(UuidInterface $trailId, $name, $description, array $posts = []) |
49
|
|
|
{ |
50
|
|
|
$this->trailId = $trailId; |
51
|
|
|
$this->name = $name; |
52
|
|
|
$this->description = $description; |
53
|
|
|
$this->posts = $posts; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @codeCoverageIgnore |
58
|
|
|
* @return UuidInterface |
59
|
|
|
*/ |
60
|
|
|
public function getTrailId(): UuidInterface |
61
|
|
|
{ |
62
|
|
|
return $this->trailId; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @codeCoverageIgnore |
67
|
|
|
* @param UuidInterface $trailId |
68
|
|
|
*/ |
69
|
|
|
public function setTrailId(UuidInterface $trailId) |
70
|
|
|
{ |
71
|
|
|
$this->trailId = $trailId; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @codeCoverageIgnore |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getName(): string |
79
|
|
|
{ |
80
|
|
|
return $this->name; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @codeCoverageIgnore |
85
|
|
|
* @param string $name |
86
|
|
|
*/ |
87
|
|
|
public function setName(string $name) |
88
|
|
|
{ |
89
|
|
|
$this->name = $name; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @codeCoverageIgnore |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function getDescription(): string |
97
|
|
|
{ |
98
|
|
|
return $this->description; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @codeCoverageIgnore |
103
|
|
|
* @param string $description |
104
|
|
|
*/ |
105
|
|
|
public function setDescription(string $description) |
106
|
|
|
{ |
107
|
|
|
$this->description = $description; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @codeCoverageIgnore |
112
|
|
|
* @return Post[] |
113
|
|
|
*/ |
114
|
|
|
public function getPosts(): array |
115
|
|
|
{ |
116
|
|
|
return $this->posts; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @codeCoverageIgnore |
121
|
|
|
* @param Post[] $posts |
122
|
|
|
*/ |
123
|
|
|
public function setPosts($posts) |
124
|
|
|
{ |
125
|
|
|
$this->posts = array_unique($posts); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param Post $post |
130
|
|
|
* @return $this |
131
|
|
|
*/ |
132
|
|
|
public function addPost(Post $post) |
133
|
|
|
{ |
134
|
|
|
$posts = $this->getPosts(); |
135
|
|
|
$posts[] = $post; |
136
|
|
|
$this->setPosts($posts); |
137
|
|
|
|
138
|
|
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param Post $post |
143
|
|
|
* @return $this |
144
|
|
|
*/ |
145
|
|
|
public function removePost(Post $post) |
146
|
|
|
{ |
147
|
|
|
foreach ($this->getPosts() as $key => $value) { |
148
|
|
|
if ($value->getPostId() === $post->getPostId()) { |
149
|
|
|
unset($this->posts[$key]); |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|