1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Website\Domain\Entities; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Domain\Entities\IStringerEntity; |
8
|
|
|
|
9
|
|
|
class Block implements IStringerEntity |
10
|
|
|
{ |
11
|
|
|
/** @var string */ |
12
|
|
|
protected $id; |
13
|
|
|
|
14
|
|
|
/** @var string */ |
15
|
|
|
protected $identifier; |
16
|
|
|
|
17
|
|
|
/** @var string */ |
18
|
|
|
protected $title; |
19
|
|
|
|
20
|
|
|
/** @var string */ |
21
|
|
|
protected $body; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
protected $layout; |
25
|
|
|
|
26
|
|
|
/** @var string|null */ |
27
|
|
|
protected $layoutId; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Block constructor. |
31
|
|
|
* |
32
|
|
|
* @param string $id |
33
|
|
|
* @param string $identifier |
34
|
|
|
* @param string $title |
35
|
|
|
* @param string $body |
36
|
|
|
* @param string $layout |
37
|
|
|
* @param string|null $layoutId |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
string $id, |
41
|
|
|
string $identifier, |
42
|
|
|
string $title, |
43
|
|
|
string $body, |
44
|
|
|
string $layout, |
45
|
|
|
string $layoutId = null |
46
|
|
|
) { |
47
|
|
|
$this->id = $id; |
48
|
|
|
$this->identifier = $identifier; |
49
|
|
|
$this->title = $title; |
50
|
|
|
$this->body = $body; |
51
|
|
|
$this->layout = $layout; |
52
|
|
|
$this->layoutId = $layoutId ? $layoutId : null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function getId() |
59
|
|
|
{ |
60
|
|
|
return $this->id; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $id |
65
|
|
|
*/ |
66
|
|
|
public function setId($id) |
67
|
|
|
{ |
68
|
|
|
$this->id = $id; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function getIdentifier(): string |
75
|
|
|
{ |
76
|
|
|
return $this->identifier; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $identifier |
81
|
|
|
* |
82
|
|
|
* @return $this |
83
|
|
|
*/ |
84
|
|
|
public function setIdentifier(string $identifier): Block |
85
|
|
|
{ |
86
|
|
|
$this->identifier = $identifier; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
public function getTitle(): string |
95
|
|
|
{ |
96
|
|
|
return $this->title; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $title |
101
|
|
|
* |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
|
|
public function setTitle(string $title): Block |
105
|
|
|
{ |
106
|
|
|
$this->title = $title; |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getBody(): string |
115
|
|
|
{ |
116
|
|
|
return $this->body; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param string $body |
121
|
|
|
* |
122
|
|
|
* @return $this |
123
|
|
|
*/ |
124
|
|
|
public function setBody(string $body): Block |
125
|
|
|
{ |
126
|
|
|
$this->body = $body; |
127
|
|
|
|
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function getLayout(): string |
135
|
|
|
{ |
136
|
|
|
return $this->layout; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string $layout |
141
|
|
|
* |
142
|
|
|
* @return $this |
143
|
|
|
*/ |
144
|
|
|
public function setLayout(string $layout): Block |
145
|
|
|
{ |
146
|
|
|
$this->layout = $layout; |
147
|
|
|
|
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return string|null |
153
|
|
|
*/ |
154
|
|
|
public function getLayoutId(): ?string |
155
|
|
|
{ |
156
|
|
|
return $this->layoutId; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param string|null $layoutId |
161
|
|
|
* |
162
|
|
|
* @return $this |
163
|
|
|
*/ |
164
|
|
|
public function setLayoutId(?string $layoutId): Block |
165
|
|
|
{ |
166
|
|
|
$this->layoutId = $layoutId; |
167
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function __toString(): string |
175
|
|
|
{ |
176
|
|
|
return $this->getIdentifier(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return array|null |
181
|
|
|
*/ |
182
|
|
|
public function toData(): ?array |
183
|
|
|
{ |
184
|
|
|
return [ |
185
|
|
|
'id' => $this->getId(), |
186
|
|
|
'identifier' => $this->getIdentifier(), |
187
|
|
|
'title' => $this->getTitle(), |
188
|
|
|
'body' => $this->getBody(), |
189
|
|
|
'layout' => $this->getLayout(), |
190
|
|
|
'layout_id' => $this->getLayoutId(), |
191
|
|
|
]; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
public function toJSON(): string |
198
|
|
|
{ |
199
|
|
|
return json_encode($this->toData()); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|