|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Sulu. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) MASSIVE ART WebServices GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sulu\Bundle\ArticleBundle\Document; |
|
13
|
|
|
|
|
14
|
|
|
use Sulu\Bundle\ArticleBundle\Document\Behavior\DateShardingBehavior; |
|
15
|
|
|
use Sulu\Bundle\ArticleBundle\Document\Behavior\RoutableBehavior; |
|
16
|
|
|
use Sulu\Bundle\RouteBundle\Model\RouteInterface; |
|
17
|
|
|
use Sulu\Component\Content\Document\Behavior\AuthorBehavior; |
|
18
|
|
|
use Sulu\Component\Content\Document\Behavior\ExtensionBehavior; |
|
19
|
|
|
use Sulu\Component\Content\Document\Behavior\LocalizedAuditableBehavior; |
|
20
|
|
|
use Sulu\Component\Content\Document\Behavior\LocalizedStructureBehavior; |
|
21
|
|
|
use Sulu\Component\Content\Document\Behavior\StructureBehavior; |
|
22
|
|
|
use Sulu\Component\Content\Document\Behavior\WorkflowStageBehavior; |
|
23
|
|
|
use Sulu\Component\Content\Document\Extension\ExtensionContainer; |
|
24
|
|
|
use Sulu\Component\Content\Document\Structure\Structure; |
|
25
|
|
|
use Sulu\Component\Content\Document\Structure\StructureInterface; |
|
26
|
|
|
use Sulu\Component\DocumentManager\Behavior\Mapping\LocalizedTitleBehavior; |
|
27
|
|
|
use Sulu\Component\DocumentManager\Behavior\Mapping\NodeNameBehavior; |
|
28
|
|
|
use Sulu\Component\DocumentManager\Behavior\Mapping\PathBehavior; |
|
29
|
|
|
use Sulu\Component\DocumentManager\Behavior\Mapping\UuidBehavior; |
|
30
|
|
|
use Sulu\Component\DocumentManager\Behavior\Path\AutoNameBehavior; |
|
31
|
|
|
use Sulu\Component\DocumentManager\Behavior\VersionBehavior; |
|
32
|
|
|
use Sulu\Component\DocumentManager\Version; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Represents an article in phpcr. |
|
36
|
|
|
*/ |
|
37
|
|
|
class ArticleDocument implements |
|
38
|
|
|
UuidBehavior, |
|
39
|
|
|
NodeNameBehavior, |
|
40
|
|
|
AutoNameBehavior, |
|
41
|
|
|
PathBehavior, |
|
42
|
|
|
LocalizedTitleBehavior, |
|
43
|
|
|
StructureBehavior, |
|
44
|
|
|
LocalizedStructureBehavior, |
|
45
|
|
|
LocalizedAuditableBehavior, |
|
46
|
|
|
DateShardingBehavior, |
|
47
|
|
|
RoutableBehavior, |
|
48
|
|
|
ExtensionBehavior, |
|
49
|
|
|
WorkflowStageBehavior, |
|
50
|
|
|
VersionBehavior, |
|
51
|
|
|
AuthorBehavior |
|
52
|
|
|
{ |
|
53
|
|
|
/** |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
private $uuid; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var string |
|
60
|
|
|
*/ |
|
61
|
|
|
private $nodeName; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var string |
|
65
|
|
|
*/ |
|
66
|
|
|
private $path; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @var object |
|
70
|
|
|
*/ |
|
71
|
|
|
private $parent; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var string |
|
75
|
|
|
*/ |
|
76
|
|
|
private $title; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @var RouteInterface |
|
80
|
|
|
*/ |
|
81
|
|
|
private $route; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @var string |
|
85
|
|
|
*/ |
|
86
|
|
|
private $routePath; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @var string |
|
90
|
|
|
*/ |
|
91
|
|
|
private $locale; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @var string |
|
95
|
|
|
*/ |
|
96
|
|
|
private $originalLocale; |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @var string |
|
100
|
|
|
*/ |
|
101
|
|
|
private $structureType; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @var StructureInterface |
|
105
|
|
|
*/ |
|
106
|
|
|
private $structure; |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @var int |
|
110
|
|
|
*/ |
|
111
|
|
|
private $creator; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @var int |
|
115
|
|
|
*/ |
|
116
|
|
|
private $changer; |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @var \DateTime |
|
120
|
|
|
*/ |
|
121
|
|
|
private $created; |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @var \DateTime |
|
125
|
|
|
*/ |
|
126
|
|
|
private $changed; |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @var int |
|
130
|
|
|
*/ |
|
131
|
|
|
private $author; |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @var \DateTime |
|
135
|
|
|
*/ |
|
136
|
|
|
private $authored; |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Document's extensions ie seo, ... |
|
140
|
|
|
* |
|
141
|
|
|
* @var ExtensionContainer |
|
142
|
|
|
*/ |
|
143
|
|
|
protected $extensions; |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Workflow Stage currently Test or Published. |
|
147
|
|
|
* |
|
148
|
|
|
* @var int |
|
149
|
|
|
*/ |
|
150
|
|
|
protected $workflowStage; |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Is Document is published. |
|
154
|
|
|
* |
|
155
|
|
|
* @var bool |
|
156
|
|
|
*/ |
|
157
|
|
|
protected $published; |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* List of versions. |
|
161
|
|
|
* |
|
162
|
|
|
* @var Version[] |
|
163
|
|
|
*/ |
|
164
|
|
|
protected $versions = []; |
|
165
|
|
|
|
|
166
|
30 |
|
public function __construct() |
|
167
|
|
|
{ |
|
168
|
30 |
|
$this->structure = new Structure(); |
|
169
|
30 |
|
$this->extensions = new ExtensionContainer(); |
|
170
|
30 |
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* {@inheritdoc} |
|
174
|
|
|
*/ |
|
175
|
30 |
|
public function getUuid() |
|
176
|
|
|
{ |
|
177
|
30 |
|
return $this->uuid; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* {@inheritdoc} |
|
182
|
|
|
*/ |
|
183
|
30 |
|
public function setUuid($uuid) |
|
184
|
|
|
{ |
|
185
|
30 |
|
$this->uuid = $uuid; |
|
186
|
30 |
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* {@inheritdoc} |
|
190
|
|
|
*/ |
|
191
|
|
|
public function getNodeName() |
|
192
|
|
|
{ |
|
193
|
|
|
return $this->nodeName; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* {@inheritdoc} |
|
198
|
|
|
*/ |
|
199
|
21 |
|
public function getPath() |
|
200
|
|
|
{ |
|
201
|
21 |
|
return $this->path; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* {@inheritdoc} |
|
206
|
|
|
*/ |
|
207
|
30 |
|
public function getParent() |
|
208
|
|
|
{ |
|
209
|
30 |
|
return $this->parent; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* {@inheritdoc} |
|
214
|
|
|
*/ |
|
215
|
30 |
|
public function setParent($document) |
|
216
|
|
|
{ |
|
217
|
30 |
|
$this->parent = $document; |
|
218
|
30 |
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* {@inheritdoc} |
|
222
|
|
|
*/ |
|
223
|
30 |
|
public function getTitle() |
|
224
|
|
|
{ |
|
225
|
30 |
|
return $this->title; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* {@inheritdoc} |
|
230
|
|
|
*/ |
|
231
|
30 |
|
public function setTitle($title) |
|
232
|
|
|
{ |
|
233
|
30 |
|
$this->title = $title; |
|
234
|
30 |
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Returns route. |
|
238
|
|
|
* |
|
239
|
|
|
* @return RouteInterface |
|
240
|
|
|
*/ |
|
241
|
30 |
|
public function getRoute() |
|
242
|
|
|
{ |
|
243
|
30 |
|
return $this->route; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* {@inheritdoc} |
|
248
|
|
|
*/ |
|
249
|
30 |
|
public function setRoute(RouteInterface $route) |
|
250
|
|
|
{ |
|
251
|
30 |
|
$this->route = $route; |
|
252
|
30 |
|
$this->routePath = $route->getPath(); |
|
253
|
30 |
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* {@inheritdoc} |
|
257
|
|
|
*/ |
|
258
|
|
|
public function removeRoute() |
|
259
|
|
|
{ |
|
260
|
|
|
$this->route = null; |
|
261
|
|
|
$this->routePath = null; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* {@inheritdoc} |
|
266
|
|
|
*/ |
|
267
|
30 |
|
public function getRoutePath() |
|
268
|
|
|
{ |
|
269
|
30 |
|
return $this->routePath; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* {@inheritdoc} |
|
274
|
|
|
*/ |
|
275
|
|
|
public function setRoutePath($routePath) |
|
276
|
|
|
{ |
|
277
|
|
|
$this->routePath = $routePath; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* {@inheritdoc} |
|
282
|
|
|
*/ |
|
283
|
30 |
|
public function getLocale() |
|
284
|
|
|
{ |
|
285
|
30 |
|
return $this->locale; |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* {@inheritdoc} |
|
290
|
|
|
*/ |
|
291
|
30 |
|
public function setLocale($locale) |
|
292
|
|
|
{ |
|
293
|
30 |
|
$this->locale = $locale; |
|
294
|
30 |
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* {@inheritdoc} |
|
298
|
|
|
*/ |
|
299
|
30 |
|
public function getOriginalLocale() |
|
300
|
|
|
{ |
|
301
|
30 |
|
return $this->originalLocale; |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* {@inheritdoc} |
|
306
|
|
|
*/ |
|
307
|
30 |
|
public function setOriginalLocale($locale) |
|
308
|
|
|
{ |
|
309
|
30 |
|
$this->originalLocale = $locale; |
|
310
|
30 |
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* {@inheritdoc} |
|
314
|
|
|
*/ |
|
315
|
30 |
|
public function getStructureType() |
|
316
|
|
|
{ |
|
317
|
30 |
|
return $this->structureType; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* {@inheritdoc} |
|
322
|
|
|
*/ |
|
323
|
30 |
|
public function setStructureType($structureType) |
|
324
|
|
|
{ |
|
325
|
30 |
|
$this->structureType = $structureType; |
|
326
|
30 |
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* {@inheritdoc} |
|
330
|
|
|
*/ |
|
331
|
30 |
|
public function getStructure() |
|
332
|
|
|
{ |
|
333
|
30 |
|
return $this->structure; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* {@inheritdoc} |
|
338
|
|
|
*/ |
|
339
|
30 |
|
public function getCreator() |
|
340
|
|
|
{ |
|
341
|
30 |
|
return $this->creator; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
/** |
|
345
|
|
|
* {@inheritdoc} |
|
346
|
|
|
*/ |
|
347
|
30 |
|
public function getChanger() |
|
348
|
|
|
{ |
|
349
|
30 |
|
return $this->changer; |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
/** |
|
353
|
|
|
* {@inheritdoc} |
|
354
|
|
|
*/ |
|
355
|
30 |
|
public function getCreated() |
|
356
|
|
|
{ |
|
357
|
30 |
|
return $this->created; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* {@inheritdoc} |
|
362
|
|
|
*/ |
|
363
|
30 |
|
public function getChanged() |
|
364
|
|
|
{ |
|
365
|
30 |
|
return $this->changed; |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* Returns identifier. |
|
370
|
|
|
* |
|
371
|
|
|
* @return mixed |
|
372
|
|
|
*/ |
|
373
|
30 |
|
public function getId() |
|
374
|
|
|
{ |
|
375
|
30 |
|
return $this->getUuid(); |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* {@inheritdoc} |
|
380
|
|
|
*/ |
|
381
|
30 |
|
public function getExtensionsData() |
|
382
|
|
|
{ |
|
383
|
30 |
|
return $this->extensions; |
|
|
|
|
|
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
/** |
|
387
|
|
|
* {@inheritdoc} |
|
388
|
|
|
*/ |
|
389
|
30 |
|
public function setExtensionsData($extensions) |
|
390
|
|
|
{ |
|
391
|
30 |
|
$this->extensions = $extensions; |
|
|
|
|
|
|
392
|
30 |
|
} |
|
393
|
|
|
|
|
394
|
|
|
/** |
|
395
|
|
|
* {@inheritdoc} |
|
396
|
|
|
*/ |
|
397
|
|
|
public function setExtension($name, $data) |
|
398
|
|
|
{ |
|
399
|
|
|
$this->extensions[$name] = $data; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
/** |
|
403
|
|
|
* {@inheritdoc} |
|
404
|
|
|
*/ |
|
405
|
32 |
|
public function getWorkflowStage() |
|
406
|
|
|
{ |
|
407
|
32 |
|
return $this->workflowStage; |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
/** |
|
411
|
|
|
* {@inheritdoc} |
|
412
|
|
|
*/ |
|
413
|
30 |
|
public function setWorkflowStage($workflowStage) |
|
414
|
|
|
{ |
|
415
|
30 |
|
$this->workflowStage = $workflowStage; |
|
416
|
30 |
|
} |
|
417
|
|
|
|
|
418
|
|
|
/** |
|
419
|
|
|
* {@inheritdoc} |
|
420
|
|
|
*/ |
|
421
|
30 |
|
public function getPublished() |
|
422
|
|
|
{ |
|
423
|
30 |
|
return $this->published; |
|
|
|
|
|
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
/** |
|
427
|
|
|
* {@inheritdoc} |
|
428
|
|
|
*/ |
|
429
|
30 |
|
public function getAuthored() |
|
430
|
|
|
{ |
|
431
|
30 |
|
return $this->authored; |
|
|
|
|
|
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
/** |
|
435
|
|
|
* {@inheritdoc} |
|
436
|
|
|
*/ |
|
437
|
30 |
|
public function setAuthored($authored) |
|
438
|
|
|
{ |
|
439
|
30 |
|
$this->authored = $authored; |
|
|
|
|
|
|
440
|
30 |
|
} |
|
441
|
|
|
|
|
442
|
|
|
/** |
|
443
|
|
|
* {@inheritdoc} |
|
444
|
|
|
*/ |
|
445
|
30 |
|
public function getAuthor() |
|
446
|
|
|
{ |
|
447
|
30 |
|
return $this->author; |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* {@inheritdoc} |
|
452
|
|
|
*/ |
|
453
|
30 |
|
public function setAuthor($author) |
|
454
|
|
|
{ |
|
455
|
30 |
|
$this->author = $author; |
|
456
|
30 |
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* {@inheritdoc} |
|
460
|
|
|
*/ |
|
461
|
|
|
public function getVersions() |
|
462
|
|
|
{ |
|
463
|
|
|
return $this->versions; |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
/** |
|
467
|
|
|
* {@inheritdoc} |
|
468
|
|
|
*/ |
|
469
|
|
|
public function setVersions($versions) |
|
470
|
|
|
{ |
|
471
|
|
|
$this->versions = $versions; |
|
472
|
|
|
} |
|
473
|
|
|
} |
|
474
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.