1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2018 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\stakx\Document; |
9
|
|
|
|
10
|
|
|
use allejo\stakx\Filesystem\File; |
11
|
|
|
|
12
|
|
|
class StaticPageView extends BasePageView implements TemplateReadyDocument |
13
|
|
|
{ |
14
|
|
|
/** @var JailedDocument */ |
15
|
|
|
private $jailInstance; |
16
|
|
|
|
17
|
|
|
/** @var JailedDocument[] */ |
18
|
|
|
private $jailedChildPageViews; |
19
|
|
|
|
20
|
|
|
/** @var StaticPageView[] */ |
21
|
|
|
private $childPageViews = []; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* StaticPageView constructor. |
25
|
|
|
*/ |
26
|
14 |
|
public function __construct(File $file) |
27
|
|
|
{ |
28
|
14 |
|
$this->type = BasePageView::STATIC_TYPE; |
29
|
|
|
|
30
|
14 |
|
parent::__construct($file); |
31
|
14 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
11 |
|
public function createJail() |
37
|
|
|
{ |
38
|
11 |
|
if ($this->jailInstance === null) |
39
|
|
|
{ |
40
|
11 |
|
$whiteListedFunctions = array_merge(self::$whiteListedFunctions, [ |
41
|
11 |
|
]); |
42
|
|
|
|
43
|
|
|
$jailedFunctions = [ |
44
|
11 |
|
'getChildren' => 'getJailedChildren', |
45
|
|
|
]; |
46
|
|
|
|
47
|
11 |
|
$this->jailInstance = new JailedDocument($this, $whiteListedFunctions, $jailedFunctions); |
48
|
|
|
} |
49
|
|
|
|
50
|
11 |
|
return $this->jailInstance; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get child PageViews. |
55
|
|
|
* |
56
|
|
|
* A child is defined as a static PageView whose URL has a parent. For example, a PageView with a URL of |
57
|
|
|
* `/gallery/france/` would have the PageView whose URL is `/gallery` as a parent. |
58
|
|
|
* |
59
|
|
|
* @return StaticPageView[] |
60
|
|
|
*/ |
61
|
3 |
|
public function &getChildren() |
62
|
|
|
{ |
63
|
3 |
|
return $this->childPageViews; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get the child PageViews. |
68
|
|
|
* |
69
|
|
|
* @return JailedDocument[] |
70
|
|
|
*/ |
71
|
3 |
|
public function getJailedChildren() |
72
|
|
|
{ |
73
|
3 |
|
if ($this->jailedChildPageViews === null) |
74
|
|
|
{ |
75
|
3 |
|
$this->jailedChildPageViews = []; |
76
|
|
|
|
77
|
3 |
|
foreach ($this->childPageViews as $key => &$child) |
78
|
|
|
{ |
79
|
3 |
|
$this->jailedChildPageViews[$key] = $child->createJail(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
3 |
|
return $this->jailedChildPageViews; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the PageView's body written in a templating language. |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getContent() |
92
|
|
|
{ |
93
|
|
|
return $this->bodyContent; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
|
View Code Duplication |
public function jsonSerialize() |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
return array_merge($this->getFrontMatter(), [ |
102
|
|
|
'content' => $this->getContent(), |
103
|
|
|
'permalink' => $this->getPermalink(), |
104
|
|
|
'redirects' => $this->getRedirects(), |
105
|
|
|
]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
protected function beforeCompile() |
109
|
|
|
{ |
110
|
|
|
$this->buildPermalink(true); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.