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