1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace allejo\stakx\Manager; |
4
|
|
|
|
5
|
|
|
use allejo\stakx\Exception\TrackedItemNotFoundException; |
6
|
|
|
use allejo\stakx\FrontMatter\ExpandedValue; |
7
|
|
|
use allejo\stakx\Object\ContentItem; |
8
|
|
|
use allejo\stakx\Object\DynamicPageView; |
9
|
|
|
use allejo\stakx\Object\PageView; |
10
|
|
|
use allejo\stakx\Object\RepeaterPageView; |
11
|
|
|
use allejo\stakx\System\FileExplorer; |
12
|
|
|
use allejo\stakx\System\Folder; |
13
|
|
|
use Twig_Error_Syntax; |
14
|
|
|
use Twig_Template; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* This class is responsible for handling all of the PageViews within a website. |
18
|
|
|
* |
19
|
|
|
* PageManager will parse all available dynamic and static PageViews. After, dynamic PageViews will be prepared by |
20
|
|
|
* setting the appropriate values for each ContentItem such as permalinks. Lastly, this class will compile all of the |
21
|
|
|
* PageViews and write them to the target directory. |
22
|
|
|
* |
23
|
|
|
* @package allejo\stakx\Manager |
24
|
|
|
*/ |
25
|
|
|
class PageManager extends TrackingManager |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* The relative (to the stakx project) file path to the redirect template |
29
|
|
|
* |
30
|
|
|
* @var string|bool |
31
|
|
|
*/ |
32
|
|
|
private $redirectTemplate; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var PageView[] |
36
|
|
|
*/ |
37
|
|
|
private $twigExtendsDeps; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var ContentItem[][] |
41
|
|
|
*/ |
42
|
|
|
private $collections; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var Folder |
46
|
|
|
*/ |
47
|
|
|
private $targetDir; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var PageView[] |
51
|
|
|
*/ |
52
|
|
|
private $flatPages; |
53
|
|
|
|
54
|
|
|
private $siteMenu; |
55
|
|
|
|
56
|
|
|
private $twigOpts; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var \Twig_Environment |
60
|
|
|
*/ |
61
|
|
|
private $twig; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* PageManager constructor |
65
|
|
|
*/ |
66
|
1 |
|
public function __construct() |
67
|
1 |
|
{ |
68
|
1 |
|
parent::__construct(); |
69
|
|
|
|
70
|
1 |
|
$this->siteMenu = array(); |
71
|
1 |
|
} |
72
|
|
|
|
73
|
1 |
|
public function setCollections (&$collections) |
74
|
|
|
{ |
75
|
|
|
if (empty($collections)) { return; } |
76
|
|
|
|
77
|
|
|
$this->collections = &$collections; |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
public function setRedirectTemplate ($filePath) |
81
|
|
|
{ |
82
|
|
|
$this->redirectTemplate = $filePath; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param Folder $folder The relative target directory as specified from the configuration file |
87
|
|
|
*/ |
88
|
1 |
|
public function setTargetFolder (&$folder) |
89
|
|
|
{ |
90
|
1 |
|
$this->targetDir = &$folder; |
91
|
1 |
|
} |
92
|
|
|
|
93
|
1 |
|
public function configureTwig ($configuration, $options) |
94
|
|
|
{ |
95
|
1 |
|
$this->twigOpts['configuration'] = $configuration; |
96
|
1 |
|
$this->twigOpts['options'] = $options; |
97
|
|
|
|
98
|
1 |
|
$this->createTwigManager(); |
99
|
1 |
|
} |
100
|
|
|
|
101
|
1 |
|
public function createTwigManager () |
102
|
|
|
{ |
103
|
1 |
|
$twig = new TwigManager(); |
104
|
1 |
|
$twig->configureTwig( |
105
|
1 |
|
$this->twigOpts['configuration'], |
106
|
1 |
|
$this->twigOpts['options'] |
107
|
1 |
|
); |
108
|
|
|
|
109
|
1 |
|
$this->twig = TwigManager::getInstance(); |
110
|
1 |
|
} |
111
|
|
|
|
112
|
|
|
public function getFlatPages () |
113
|
|
|
{ |
114
|
|
|
return $this->flatPages; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* An array representing the website's menu structure with children and grandchildren made from static PageViews |
119
|
|
|
* |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
|
|
public function getSiteMenu () |
123
|
|
|
{ |
124
|
|
|
return $this->siteMenu; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Go through all of the PageView directories and create a respective PageView for each and classify them as a |
129
|
|
|
* dynamic or static PageView. |
130
|
|
|
* |
131
|
|
|
* @param $pageViewFolders |
132
|
|
|
*/ |
133
|
1 |
|
public function parsePageViews ($pageViewFolders) |
134
|
|
|
{ |
135
|
1 |
|
if (empty($pageViewFolders)) { return; } |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* The name of the folder where PageViews are located |
139
|
|
|
* |
140
|
|
|
* @var $pageViewFolder string |
141
|
|
|
*/ |
142
|
1 |
|
foreach ($pageViewFolders as $pageViewFolderName) |
143
|
|
|
{ |
144
|
1 |
|
$pageViewFolder = $this->fs->absolutePath($pageViewFolderName); |
145
|
|
|
|
146
|
1 |
|
if (!$this->fs->exists($pageViewFolder)) |
147
|
1 |
|
{ |
148
|
|
|
continue; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
// @TODO Replace this with a regular expression or have wildcard support |
|
|
|
|
152
|
1 |
|
$this->scanTrackableItems($pageViewFolder, array( |
153
|
1 |
|
'refresh' => false, |
154
|
|
|
'fileExplorer' => FileExplorer::INCLUDE_ONLY_FILES |
155
|
1 |
|
), array('.html', '.twig')); |
156
|
1 |
|
$this->saveFolderDefinition($pageViewFolderName); |
157
|
1 |
|
} |
158
|
1 |
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Compile dynamic and static PageViews |
162
|
|
|
*/ |
163
|
1 |
|
public function compileAll () |
164
|
|
|
{ |
165
|
1 |
|
foreach (array_keys($this->trackedItemsFlattened) as $filePath) |
166
|
|
|
{ |
167
|
1 |
|
$this->compileFromFilePath($filePath); |
168
|
1 |
|
} |
169
|
1 |
|
} |
170
|
|
|
|
171
|
|
|
public function compileSome ($filter = array()) |
172
|
|
|
{ |
173
|
|
|
/** @var PageView $pageView */ |
174
|
|
|
foreach ($this->trackedItemsFlattened as $pageView) |
175
|
|
|
{ |
176
|
|
|
if ($pageView->hasTwigDependency($filter['namespace'], $filter['dependency'])) |
177
|
|
|
{ |
178
|
|
|
$this->compilePageView($pageView); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param ContentItem $contentItem |
185
|
|
|
*/ |
186
|
|
|
public function compileContentItem (&$contentItem) |
187
|
|
|
{ |
188
|
|
|
$pageView = $contentItem->getPageView(); |
189
|
|
|
|
190
|
|
|
// This ContentItem doesn't have an individual PageView dedicated to displaying this item |
191
|
|
|
if (is_null($pageView)) |
192
|
|
|
{ |
193
|
|
|
return; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
$template = $this->createTemplate($pageView); |
197
|
|
|
$contentItem->evaluateFrontMatter( |
198
|
|
|
$pageView->getFrontMatter(false) |
199
|
|
|
); |
200
|
|
|
|
201
|
|
|
$output = $template->render(array( |
202
|
|
|
'this' => $contentItem |
203
|
|
|
)); |
204
|
|
|
|
205
|
|
|
$this->targetDir->writeFile($contentItem->getTargetFile(), $output); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Add a new ContentItem to the respective parent PageView of the ContentItem |
210
|
|
|
* |
211
|
|
|
* @param ContentItem $contentItem |
212
|
|
|
*/ |
213
|
|
|
public function updatePageView ($contentItem) |
214
|
|
|
{ |
215
|
|
|
/** @var DynamicPageView $pageView */ |
216
|
|
|
foreach ($this->trackedItems['dynamic'] as &$pageView) |
217
|
|
|
{ |
218
|
|
|
$fm = $pageView->getFrontMatter(false); |
219
|
|
|
|
220
|
|
|
if ($fm['collection'] == $contentItem->getCollection()) |
221
|
|
|
{ |
222
|
|
|
$pageView->addContentItem($contentItem); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Update an existing Twig variable that's injected globally |
229
|
|
|
* |
230
|
|
|
* @param string $variable |
231
|
|
|
* @param string $value |
232
|
|
|
*/ |
233
|
|
|
public function updateTwigVariable ($variable, $value) |
234
|
|
|
{ |
235
|
|
|
$this->twig->addGlobal($variable, $value); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* {@inheritdoc} |
240
|
|
|
*/ |
241
|
1 |
|
public function isTracked($filePath) |
242
|
|
|
{ |
243
|
1 |
|
return (parent::isTracked($filePath) || isset($this->twigExtendsDeps[$filePath])); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* {@inheritdoc} |
248
|
|
|
*/ |
249
|
|
|
public function refreshItem($filePath) |
250
|
|
|
{ |
251
|
|
|
if (parent::isTracked($filePath)) |
|
|
|
|
252
|
|
|
{ |
253
|
|
|
$this->compileFromFilePath($filePath, true); |
254
|
|
|
|
255
|
|
|
return; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
$this->createTwigManager(); |
259
|
|
|
|
260
|
|
|
foreach ($this->twigExtendsDeps[$filePath] as $pageView) |
|
|
|
|
261
|
|
|
{ |
262
|
|
|
$this->compilePageView($pageView); |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* {@inheritdoc} |
268
|
|
|
*/ |
269
|
1 |
|
protected function handleTrackableItem($filePath, $options = array()) |
270
|
|
|
{ |
271
|
1 |
|
$pageView = PageView::create($filePath); |
272
|
1 |
|
$namespace = $pageView->getType(); |
273
|
|
|
|
274
|
1 |
|
if ($namespace == PageView::DYNAMIC_TYPE) |
275
|
1 |
|
{ |
276
|
1 |
|
$frontMatter = $pageView->getFrontMatter(false); |
277
|
|
|
$collection = $frontMatter['collection']; |
278
|
|
|
|
279
|
|
|
foreach ($this->collections[$collection] as &$item) |
280
|
|
|
{ |
281
|
|
|
$item->evaluateFrontMatter($frontMatter); |
282
|
|
|
$pageView->addContentItem($item); |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
|
286
|
1 |
|
$this->addObjectToTracker($pageView, $pageView->getRelativeFilePath(), $namespace); |
287
|
1 |
|
$this->saveTrackerOptions($pageView->getRelativeFilePath(), array( |
288
|
|
|
'viewType' => $namespace |
289
|
1 |
|
)); |
290
|
|
|
|
291
|
1 |
|
if ($namespace == PageView::STATIC_TYPE) |
292
|
1 |
|
{ |
293
|
|
|
$this->addToSiteMenu($pageView); |
294
|
|
|
|
295
|
|
|
if (!empty($pageView->title)) { |
|
|
|
|
296
|
|
|
$this->flatPages[$pageView->title] = &$pageView; |
|
|
|
|
297
|
|
|
} |
298
|
|
|
} |
299
|
1 |
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Compile a given PageView |
303
|
|
|
* |
304
|
|
|
* @param string $filePath The file path to the PageView to compile |
305
|
|
|
* @param bool $refresh When set to true, the PageView will reread its contents |
306
|
|
|
* |
307
|
|
|
* @throws \Exception |
308
|
|
|
*/ |
309
|
1 |
|
private function compileFromFilePath ($filePath, $refresh = false) |
310
|
|
|
{ |
311
|
1 |
|
if (!$this->isTracked($filePath)) |
312
|
1 |
|
{ |
313
|
|
|
throw new TrackedItemNotFoundException('PageView not found'); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** @var DynamicPageView|PageView|RepeaterPageView $pageView */ |
317
|
1 |
|
$pageView = &$this->trackedItemsFlattened[$filePath]; |
318
|
|
|
|
319
|
1 |
|
$this->compilePageView($pageView, $refresh); |
320
|
1 |
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @param DynamicPageView|PageView|RepeaterPageView $pageView |
324
|
|
|
* @param bool $refresh |
325
|
|
|
*/ |
326
|
1 |
|
private function compilePageView ($pageView, $refresh = false) |
327
|
|
|
{ |
328
|
|
|
if ($refresh) |
329
|
1 |
|
{ |
330
|
|
|
$pageView->refreshFileContent(); |
331
|
|
|
} |
332
|
|
|
|
333
|
1 |
|
switch ($pageView->getType()) |
334
|
|
|
{ |
335
|
1 |
|
case PageView::REPEATER_TYPE: |
336
|
1 |
|
$this->compileRepeaterPageView($pageView); |
|
|
|
|
337
|
1 |
|
$this->compileExpandedRedirects($pageView); |
338
|
1 |
|
break; |
339
|
|
|
|
340
|
|
|
case PageView::DYNAMIC_TYPE: |
341
|
|
|
$this->compileDynamicPageView($pageView); |
342
|
|
|
$this->compileNormalRedirects($pageView); |
343
|
|
|
break; |
344
|
|
|
|
345
|
|
|
case PageView::STATIC_TYPE: |
346
|
|
|
$this->compileStaticPageView($pageView); |
347
|
|
|
$this->compileNormalRedirects($pageView); |
348
|
|
|
break; |
349
|
1 |
|
} |
350
|
1 |
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @param RepeaterPageView $pageView |
354
|
|
|
*/ |
355
|
1 |
|
private function compileRepeaterPageView (&$pageView) |
356
|
|
|
{ |
357
|
1 |
|
$template = $this->createTemplate($pageView); |
358
|
1 |
|
$pageView->rewindPermalink(); |
|
|
|
|
359
|
|
|
|
360
|
1 |
|
foreach ($pageView->getRepeaterPermalinks() as $permalink) |
|
|
|
|
361
|
|
|
{ |
362
|
1 |
|
$pageView->bumpPermalink(); |
|
|
|
|
363
|
1 |
|
$pageView->setFrontMatter(array( |
364
|
1 |
|
'permalink' => $permalink->getEvaluated(), |
365
|
1 |
|
'iterators' => $permalink->getIterators() |
366
|
1 |
|
)); |
367
|
|
|
|
368
|
1 |
|
$output = $template->render(array( |
369
|
1 |
|
'this' => $pageView->createJail() |
370
|
1 |
|
)); |
371
|
|
|
|
372
|
1 |
|
$this->output->notice("Writing repeater file: {file}", array('file' => $pageView->getTargetFile())); |
373
|
1 |
|
$this->targetDir->writeFile($pageView->getTargetFile(), $output); |
374
|
1 |
|
} |
375
|
1 |
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @param PageView $pageView |
379
|
|
|
*/ |
380
|
|
|
private function compileDynamicPageView (&$pageView) |
381
|
|
|
{ |
382
|
|
|
$template = $this->createTemplate($pageView); |
383
|
|
|
|
384
|
|
|
$pageViewFrontMatter = $pageView->getFrontMatter(false); |
385
|
|
|
$collection = $pageViewFrontMatter['collection']; |
386
|
|
|
|
387
|
|
|
/** @var ContentItem $contentItem */ |
388
|
|
|
foreach ($this->collections[$collection] as &$contentItem) |
389
|
|
|
{ |
390
|
|
|
$output = $template->render(array( |
391
|
|
|
'this' => $contentItem->createJail() |
392
|
|
|
)); |
393
|
|
|
|
394
|
|
|
$this->output->notice("Writing file: {file}", array('file' => $contentItem->getTargetFile())); |
395
|
|
|
$this->targetDir->writeFile($contentItem->getTargetFile(), $output); |
396
|
|
|
} |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @param PageView $pageView |
401
|
|
|
*/ |
402
|
|
|
private function compileStaticPageView (&$pageView) |
403
|
|
|
{ |
404
|
|
|
$this->twig->addGlobal('__currentTemplate', $pageView->getFilePath()); |
405
|
|
|
|
406
|
|
|
$template = $this->createTemplate($pageView); |
407
|
|
|
$output = $template->render(array( |
408
|
|
|
'this' => $pageView->createJail() |
409
|
|
|
)); |
410
|
|
|
|
411
|
|
|
$this->output->notice("Writing file: {file}", array('file' => $pageView->getTargetFile())); |
412
|
|
|
$this->targetDir->writeFile($pageView->getTargetFile(), $output); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* @param DynamicPageView|PageView $pageView |
417
|
|
|
*/ |
418
|
|
|
private function compileNormalRedirects (&$pageView) |
419
|
|
|
{ |
420
|
|
|
foreach ($pageView->getRedirects() as $redirect) |
|
|
|
|
421
|
|
|
{ |
422
|
|
|
$redirectPageView = PageView::createRedirect( |
423
|
|
|
$redirect, |
424
|
|
|
$pageView->getPermalink(), |
425
|
|
|
$this->redirectTemplate |
426
|
|
|
); |
427
|
|
|
|
428
|
|
|
$this->compilePageView($redirectPageView); |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* @param RepeaterPageView $pageView |
434
|
|
|
*/ |
435
|
1 |
|
private function compileExpandedRedirects (&$pageView) |
436
|
|
|
{ |
437
|
1 |
|
$permalinks = $pageView->getRepeaterPermalinks(); |
438
|
|
|
|
439
|
|
|
/** @var ExpandedValue[] $repeaterRedirect */ |
440
|
1 |
|
foreach ($pageView->getRepeaterRedirects() as $repeaterRedirect) |
441
|
|
|
{ |
442
|
|
|
/** |
443
|
|
|
* @var int $index |
444
|
|
|
* @var ExpandedValue $redirect |
445
|
|
|
*/ |
446
|
|
|
foreach ($repeaterRedirect as $index => $redirect) |
447
|
|
|
{ |
448
|
|
|
$redirectPageView = PageView::createRedirect( |
449
|
|
|
$redirect->getEvaluated(), |
450
|
|
|
$permalinks[$index]->getEvaluated(), |
451
|
|
|
$this->redirectTemplate |
452
|
|
|
); |
453
|
|
|
|
454
|
|
|
$this->compilePageView($redirectPageView); |
455
|
|
|
} |
456
|
1 |
|
} |
457
|
1 |
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* Add a static PageView to the menu array. Dynamic PageViews are not added to the menu |
461
|
|
|
* |
462
|
|
|
* @param PageView $pageView |
463
|
|
|
*/ |
464
|
1 |
|
private function addToSiteMenu (&$pageView) |
465
|
|
|
{ |
466
|
|
|
$frontMatter = $pageView->getFrontMatter(); |
467
|
|
|
|
468
|
|
|
if (!array_key_exists('permalink', $frontMatter) || |
469
|
|
|
(array_key_exists('menu', $frontMatter) && !$frontMatter['menu'])) |
470
|
|
|
{ |
471
|
|
|
return; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
$url = $pageView->getPermalink(); |
475
|
|
|
$root = &$this->siteMenu; |
476
|
|
|
$permalink = trim($url, DIRECTORY_SEPARATOR); |
477
|
|
|
$dirs = explode(DIRECTORY_SEPARATOR, $permalink); |
478
|
|
|
|
479
|
|
|
while (count($dirs) > 0) |
480
|
|
|
{ |
481
|
|
|
$name = array_shift($dirs); |
482
|
|
|
$name = (!empty($name)) ? $name : '.'; |
483
|
|
|
|
484
|
|
|
if (!is_null($name) && count($dirs) == 0) |
485
|
|
|
{ |
486
|
1 |
|
$children = array(); |
487
|
|
|
|
488
|
|
|
if (array_key_exists($name, $root) && is_array($root[$name])) |
489
|
|
|
{ |
490
|
|
|
$children = $root[$name]['children']; |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
$root[$name] = &$pageView; |
494
|
|
|
$root = &$root[$name]->getChildren(); |
495
|
|
|
|
496
|
|
|
if (!empty($children)) |
497
|
|
|
{ |
498
|
|
|
$root = $children; |
499
|
|
|
} |
500
|
|
|
} |
501
|
|
|
else |
502
|
|
|
{ |
503
|
|
|
$root[$name]['children'] = array(); |
504
|
|
|
$root = &$root[$name]['children']; |
505
|
|
|
} |
506
|
|
|
} |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
/** |
510
|
|
|
* @param PageView $pageView |
511
|
|
|
* |
512
|
|
|
* @return Twig_Template |
513
|
|
|
* @throws Twig_Error_Syntax |
514
|
|
|
*/ |
515
|
1 |
|
private function createTemplate (&$pageView) |
516
|
|
|
{ |
517
|
|
|
try |
518
|
|
|
{ |
519
|
1 |
|
$template = $this->twig->createTemplate($pageView->getContent()); |
520
|
|
|
|
521
|
1 |
|
$this->trackParentTwigTemplate($template, $pageView); |
522
|
|
|
|
523
|
1 |
|
return $template; |
524
|
|
|
} |
525
|
|
|
catch (Twig_Error_Syntax $e) |
526
|
|
|
{ |
527
|
|
|
$e->setTemplateLine($e->getTemplateLine() + $pageView->getLineOffset()); |
528
|
|
|
$e->setTemplateName($pageView->getRelativeFilePath()); |
529
|
|
|
|
530
|
|
|
throw $e; |
531
|
|
|
} |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* Find the parent Twig templates of the given template and keep a list of it |
536
|
|
|
* |
537
|
|
|
* @param Twig_Template $template The template created from the PageView's content |
538
|
|
|
* @param PageView $pageView The PageView that has this content. Used to keep a reference of PageViews |
539
|
|
|
*/ |
540
|
1 |
|
private function trackParentTwigTemplate ($template, &$pageView) |
541
|
|
|
{ |
542
|
1 |
|
if (!$this->tracking) { return; } |
543
|
|
|
|
544
|
|
|
/** @var Twig_Template $parent */ |
545
|
|
|
$parent = $template->getParent(array()); |
546
|
|
|
|
547
|
|
|
while ($parent !== false) |
548
|
|
|
{ |
549
|
|
|
$filePath = $this->fs->getRelativePath($parent->getSourceContext()->getPath()); |
550
|
|
|
|
551
|
|
|
$this->twigExtendsDeps[$filePath][(string)$pageView->getFilePath()] = &$pageView; |
552
|
|
|
$parent = $parent->getParent(array()); |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
} |