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
|
|
|
use allejo\stakx\FrontMatter\ExpandedValue; |
12
|
|
|
|
13
|
|
|
class RepeaterPageView extends BasePageView implements TemplateReadyDocument |
14
|
|
|
{ |
15
|
|
|
/** @var \ArrayIterator An iterator for the permalinks used in order for this entity to be treated as a static PageView. */ |
16
|
|
|
private $permalinksIterator; |
17
|
|
|
|
18
|
|
|
/** @var ExpandedValue[] All of the expanded permalinks. */ |
19
|
|
|
private $permalinks; |
20
|
|
|
|
21
|
|
|
/** @var ExpandedValue[][] All of expanded redirects that should point to the respective permalink; this is estimated by index. */ |
22
|
|
|
private $redirectLinks; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* RepeaterPageView constructor. |
26
|
|
|
*/ |
27
|
3 |
|
public function __construct(File $file) |
28
|
|
|
{ |
29
|
3 |
|
parent::__construct($file); |
30
|
|
|
|
31
|
3 |
|
$this->type = BasePageView::REPEATER_TYPE; |
32
|
3 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get the permalink matching all the placeholders for a Repeater. |
36
|
|
|
* |
37
|
|
|
* @param array $where |
38
|
|
|
* |
39
|
|
|
* @return null|string |
40
|
|
|
*/ |
41
|
|
|
public function _getPermalinkWhere(array $where) |
42
|
|
|
{ |
43
|
|
|
foreach ($this->permalinks as $expandedValue) |
44
|
|
|
{ |
45
|
|
|
if ($expandedValue->getIterators() === $where) |
46
|
|
|
{ |
47
|
|
|
return $expandedValue->getEvaluated(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the expanded values for the permalinks to this PageView. |
56
|
|
|
* |
57
|
|
|
* @return ExpandedValue[] |
58
|
|
|
*/ |
59
|
3 |
|
public function getRepeaterPermalinks() |
60
|
|
|
{ |
61
|
3 |
|
return $this->permalinks; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the expanded values for the redirects pointing to this PageView. |
66
|
|
|
* |
67
|
|
|
* @return ExpandedValue[][] |
68
|
|
|
*/ |
69
|
3 |
|
public function getRepeaterRedirects() |
70
|
|
|
{ |
71
|
3 |
|
return $this->redirectLinks; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* When looping through permalinks in a RepeaterPageView, the permalink needs to be updated each time so that it may |
76
|
|
|
* behave as a static PageView. |
77
|
|
|
*/ |
78
|
3 |
|
public function bumpPermalink() |
79
|
|
|
{ |
80
|
3 |
|
$this->permalink = $this->permalinksIterator->current()->getEvaluated(); |
81
|
3 |
|
$this->permalinksIterator->next(); |
82
|
3 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Rewind the permalink iterator to the beginning. |
86
|
|
|
*/ |
87
|
3 |
|
public function rewindPermalink() |
88
|
|
|
{ |
89
|
3 |
|
$this->permalinksIterator->rewind(); |
90
|
3 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Configure permalinks from expanded values internally. |
94
|
|
|
*/ |
95
|
3 |
|
public function configurePermalinks() |
96
|
|
|
{ |
97
|
3 |
|
$evaluated = $this->frontMatter['permalink']; |
98
|
|
|
|
99
|
3 |
|
$this->permalinks = $evaluated[0]; |
100
|
3 |
|
array_shift($evaluated); |
101
|
3 |
|
$this->redirectLinks = $evaluated; |
102
|
|
|
|
103
|
3 |
|
$this->permalinksIterator = new \ArrayIterator($this->permalinks); |
104
|
3 |
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
3 |
|
public function buildPermalink($force = false) |
110
|
|
|
{ |
111
|
3 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
3 |
|
public function createJail() |
117
|
|
|
{ |
118
|
3 |
|
$whitelist = array_merge(self::$whiteListedFunctions, [ |
119
|
3 |
|
'_getPermalinkWhere', |
120
|
|
|
]); |
121
|
|
|
|
122
|
3 |
|
return new JailedDocument($this, $whitelist); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* {@inheritdoc} |
127
|
|
|
*/ |
128
|
|
|
public function jsonSerialize() |
129
|
|
|
{ |
130
|
|
|
return []; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|