Completed
Push — master ( 50fad5...73a623 )
by Vladimir
03:52
created

PageManager::setRedirectTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace allejo\stakx\Manager;
4
5
use allejo\stakx\Exception\FileAwareException;
6
use allejo\stakx\Exception\TrackedItemNotFoundException;
7
use allejo\stakx\FrontMatter\ExpandedValue;
8
use allejo\stakx\Object\ContentItem;
9
use allejo\stakx\Object\DynamicPageView;
10
use allejo\stakx\Object\JailObject;
11
use allejo\stakx\Object\PageView;
12
use allejo\stakx\Object\RepeaterPageView;
13
use allejo\stakx\System\FileExplorer;
14
use allejo\stakx\System\Folder;
15
use Twig_Error_Syntax;
16
use Twig_Template;
17
18
/**
19
 * This class is responsible for handling all of the PageViews within a website.
20
 *
21
 * PageManager will parse all available dynamic and static PageViews. After, dynamic PageViews will be prepared by
22
 * setting the appropriate values for each ContentItem such as permalinks. Lastly, this class will compile all of the
23
 * PageViews and write them to the target directory.
24
 *
25
 * @package allejo\stakx\Manager
26
 */
27
class PageManager extends TrackingManager
28
{
29
    /**
30
     * The relative (to the stakx project) file path to the redirect template
31
     *
32
     * @var string|bool
33
     */
34
    private $redirectTemplate;
35
36
    /**
37
     * @var PageView[]
38
     */
39
    private $twigExtendsDeps;
40
41
    /**
42
     * @var ContentItem[][]
43
     */
44
    private $collections;
45
46
    /**
47
     * @var Folder
48
     */
49
    private $targetDir;
50
51
    /**
52
     * @var PageView[]
53
     */
54
    private $flatPages;
55
56
    /**
57
     * @var PageView[]
58
     */
59
    private $siteMenu;
60
61
    /**
62
     * @var array
63
     */
64
    private $twigOpts;
65
66
    /**
67
     * @var \Twig_Environment
68
     */
69
    private $twig;
70
71
    /**
72
     * PageManager constructor
73
     */
74 4
    public function __construct()
75
    {
76 4
        parent::__construct();
77
78 4
        $this->redirectTemplate = false;
79 4
        $this->twigExtendsDeps = array();
80 4
        $this->collections = array();
81 4
        $this->flatPages = array();
82 4
        $this->siteMenu = array();
83 4
    }
84
85
    /**
86
     * Give this manager the collections we'll be using for dynamic PageViews
87
     *
88
     * @param ContentItem[][] $collections
89
     */
90 1
    public function setCollections (&$collections)
91
    {
92 1
        $this->collections = &$collections;
93 1
    }
94
95
    /**
96
     * Set the template used for redirects
97
     *
98
     * @param false|string $filePath The path to the redirect template
99
     */
100 1
    public function setRedirectTemplate ($filePath)
101
    {
102 1
        $this->redirectTemplate = $filePath;
103 1
    }
104
105
    /**
106
     * The location where the compiled website will be written to
107
     *
108
     * @param Folder $folder The relative target directory as specified from the configuration file
109
     */
110 4
    public function setTargetFolder (&$folder)
111
    {
112 4
        $this->targetDir = &$folder;
113 4
    }
114
115 1
    public function configureTwig ($configuration, $options)
116
    {
117 1
        $this->twigOpts['configuration'] = $configuration;
118 1
        $this->twigOpts['options']       = $options;
119
120 1
        $this->createTwigManager();
121 1
    }
122
123 1
    public function getFlatPages ()
124
    {
125 1
        return $this->flatPages;
126
    }
127
128
    /**
129
     * An array representing the website's menu structure with children and grandchildren made from static PageViews
130
     *
131
     * @return JailObject[]
132
     */
133 1
    public function getSiteMenu ()
134
    {
135 1
        $jailedMenu = array();
136
137 1
        foreach ($this->siteMenu as $key => $value)
138
        {
139
            // If it's an array, it means the parent is hidden from the site menu therefore its children should be too
140
            if (is_array($this->siteMenu[$key]))
141
            {
142
                continue;
143
            }
144
145
            $jailedMenu[$key] = $value->createJail();
146
        }
147
148 1
        return $jailedMenu;
149
    }
150
151
    /**
152
     * Go through all of the PageView directories and create a respective PageView for each and classify them as a
153
     * dynamic or static PageView.
154
     *
155
     * @param $pageViewFolders
156
     */
157 4
    public function parsePageViews ($pageViewFolders)
158
    {
159 4
        if (empty($pageViewFolders)) { return; }
160
161
        /**
162
         * The name of the folder where PageViews are located
163
         *
164
         * @var $pageViewFolder string
165
         */
166 4
        foreach ($pageViewFolders as $pageViewFolderName)
167
        {
168 4
            $pageViewFolder = $this->fs->absolutePath($pageViewFolderName);
169
170 4
            if (!$this->fs->exists($pageViewFolder))
171
            {
172 1
                continue;
173
            }
174
175
            // @TODO Replace this with a regular expression or have wildcard support
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
176 3
            $this->scanTrackableItems($pageViewFolder, array(
177 3
                'refresh' => false,
178
                'fileExplorer' => FileExplorer::INCLUDE_ONLY_FILES
179 3
            ), array('.html', '.twig'));
180
            $this->saveFolderDefinition($pageViewFolderName);
181
        }
182 1
    }
183
184
    /**
185
     * Compile dynamic and static PageViews
186
     */
187 1
    public function compileAll ()
188
    {
189 1
        foreach (array_keys($this->trackedItemsFlattened) as $filePath)
190
        {
191
            $this->compileFromFilePath($filePath);
192
        }
193 1
    }
194
195
    public function compileSome ($filter = array())
196
    {
197
        /** @var PageView $pageView */
198
        foreach ($this->trackedItemsFlattened as $pageView)
199
        {
200
            if ($pageView->hasTwigDependency($filter['namespace'], $filter['dependency']))
201
            {
202
                $this->compilePageView($pageView);
203
            }
204
        }
205
    }
206
207
    /**
208
     * @param ContentItem $contentItem
209
     */
210
    public function compileContentItem (&$contentItem)
211
    {
212
        $pageView = $contentItem->getPageView();
213
214
        // This ContentItem doesn't have an individual PageView dedicated to displaying this item
215
        if (is_null($pageView))
216
        {
217
            return;
218
        }
219
220
        $template = $this->createTemplate($pageView);
221
        $contentItem->evaluateFrontMatter(
222
            $pageView->getFrontMatter(false)
223
        );
224
225
        $output = $template->render(array(
226
            'this' => $contentItem
227
        ));
228
229
        $this->targetDir->writeFile($contentItem->getTargetFile(), $output);
230
    }
231
232
    /**
233
     * Add a new ContentItem to the respective parent PageView of the ContentItem
234
     *
235
     * @param ContentItem $contentItem
236
     */
237
    public function updatePageView ($contentItem)
238
    {
239
        /** @var DynamicPageView $pageView */
240
        foreach ($this->trackedItems['dynamic'] as &$pageView)
241
        {
242
            $fm = $pageView->getFrontMatter(false);
243
244
            if ($fm['collection'] == $contentItem->getCollection())
245
            {
246
                $pageView->addContentItem($contentItem);
247
            }
248
        }
249
    }
250
251
    /**
252
     * Update an existing Twig variable that's injected globally
253
     *
254
     * @param string $variable
255
     * @param string $value
256
     */
257
    public function updateTwigVariable ($variable, $value)
258
    {
259
        $this->twig->addGlobal($variable, $value);
260
    }
261
262
    /**
263
     * {@inheritdoc}
264
     */
265
    public function isTracked($filePath)
266
    {
267
        return (parent::isTracked($filePath) || isset($this->twigExtendsDeps[$filePath]));
268
    }
269
270
    /**
271
     * {@inheritdoc}
272
     */
273
    public function refreshItem($filePath)
274
    {
275
        if (parent::isTracked($filePath))
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (isTracked() instead of refreshItem()). Are you sure this is correct? If so, you might want to change this to $this->isTracked().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
276
        {
277
            $this->compileFromFilePath($filePath, true);
278
279
            return;
280
        }
281
282
        $this->createTwigManager();
283
284
        foreach ($this->twigExtendsDeps[$filePath] as $pageView)
0 ignored issues
show
Bug introduced by
The expression $this->twigExtendsDeps[$filePath] of type object<allejo\stakx\Object\PageView> is not traversable.
Loading history...
285
        {
286
            $this->compilePageView($pageView);
287
        }
288
    }
289
290
    /**
291
     * {@inheritdoc}
292
     */
293 3
    protected function handleTrackableItem($filePath, $options = array())
294
    {
295 3
        $pageView  = PageView::create($filePath);
296 3
        $namespace = $pageView->getType();
297
298 3
        if ($namespace == PageView::DYNAMIC_TYPE)
299
        {
300 3
            $frontMatter = $pageView->getFrontMatter(false);
301 3
            $collection = $frontMatter['collection'];
302
303 3
            foreach ($this->collections[$collection] as &$item)
304
            {
305
                $item->evaluateFrontMatter($frontMatter);
306
                $pageView->addContentItem($item);
307
            }
308
        }
309
310
        $this->addObjectToTracker($pageView, $pageView->getRelativeFilePath(), $namespace);
311
        $this->saveTrackerOptions($pageView->getRelativeFilePath(), array(
312
            'viewType' => $namespace
313
        ));
314
315
        if ($namespace == PageView::STATIC_TYPE && !empty($pageView['title']))
316
        {
317
            $this->addToSiteMenu($pageView);
318
            $this->flatPages[$pageView['title']] = $pageView->createJail();
319
        }
320
    }
321
322
    /**
323
     * Create a Twig environment
324
     */
325 1
    private function createTwigManager ()
326
    {
327 1
        $twig = new TwigManager();
328 1
        $twig->configureTwig(
329 1
            $this->twigOpts['configuration'],
330 1
            $this->twigOpts['options']
331
        );
332
333 1
        $this->twig = TwigManager::getInstance();
334 1
    }
335
336
    /**
337
     * Compile a given PageView
338
     *
339
     * @param string $filePath The file path to the PageView to compile
340
     * @param bool   $refresh  When set to true, the PageView will reread its contents
341
     *
342
     * @throws \Exception
343
     */
344
    private function compileFromFilePath ($filePath, $refresh = false)
345
    {
346
        if (!$this->isTracked($filePath))
347
        {
348
            throw new TrackedItemNotFoundException('PageView not found');
349
        }
350
351
        /** @var DynamicPageView|PageView|RepeaterPageView $pageView */
352
        $pageView = &$this->trackedItemsFlattened[$filePath];
353
354
        try
355
        {
356
            $this->compilePageView($pageView, $refresh);
357
        }
358
        catch (\Exception $e)
359
        {
360
            throw FileAwareException::castException($e, $filePath);
361
        }
362
    }
363
364
    /**
365
     * @param DynamicPageView|PageView|RepeaterPageView $pageView
366
     * @param bool                                      $refresh
367
     */
368
    private function compilePageView ($pageView, $refresh = false)
369
    {
370
        if ($refresh)
371
        {
372
            $pageView->refreshFileContent();
373
        }
374
375
        switch ($pageView->getType())
376
        {
377
            case PageView::REPEATER_TYPE:
378
                $this->compileRepeaterPageView($pageView);
0 ignored issues
show
Compatibility introduced by
$pageView of type object<allejo\stakx\Object\PageView> is not a sub-type of object<allejo\stakx\Object\RepeaterPageView>. It seems like you assume a child class of the class allejo\stakx\Object\PageView to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
379
                $this->compileExpandedRedirects($pageView);
380
                break;
381
382
            case PageView::DYNAMIC_TYPE:
383
                $this->compileDynamicPageView($pageView);
384
                $this->compileNormalRedirects($pageView);
385
                break;
386
387
            case PageView::STATIC_TYPE:
388
                $this->compileStaticPageView($pageView);
389
                $this->compileNormalRedirects($pageView);
390
                break;
391
        }
392
    }
393
394
    /**
395
     * @param RepeaterPageView $pageView
396
     */
397
    private function compileRepeaterPageView (&$pageView)
398
    {
399
        $template = $this->createTemplate($pageView);
400
        $pageView->rewindPermalink();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class allejo\stakx\Object\PageView as the method rewindPermalink() does only exist in the following sub-classes of allejo\stakx\Object\PageView: allejo\stakx\Object\RepeaterPageView. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
401
402
        foreach ($pageView->getRepeaterPermalinks() as $permalink)
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class allejo\stakx\Object\PageView as the method getRepeaterPermalinks() does only exist in the following sub-classes of allejo\stakx\Object\PageView: allejo\stakx\Object\RepeaterPageView. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
403
        {
404
            $pageView->bumpPermalink();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class allejo\stakx\Object\PageView as the method bumpPermalink() does only exist in the following sub-classes of allejo\stakx\Object\PageView: allejo\stakx\Object\RepeaterPageView. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
405
            $pageView->setFrontMatter(array(
406
                'permalink' => $permalink->getEvaluated(),
407
                'iterators' => $permalink->getIterators()
408
            ));
409
410
            $output = $template->render(array(
411
                'this' => $pageView->createJail()
412
            ));
413
414
            $this->output->notice("Writing repeater file: {file}", array('file' => $pageView->getTargetFile()));
415
            $this->targetDir->writeFile($pageView->getTargetFile(), $output);
416
        }
417
    }
418
419
    /**
420
     * @param PageView $pageView
421
     */
422
    private function compileDynamicPageView (&$pageView)
423
    {
424
        $template = $this->createTemplate($pageView);
425
426
        $pageViewFrontMatter = $pageView->getFrontMatter(false);
427
        $collection = $pageViewFrontMatter['collection'];
428
429
        /** @var ContentItem $contentItem */
430
        foreach ($this->collections[$collection] as &$contentItem)
431
        {
432
            $output = $template->render(array(
433
                'this' => $contentItem->createJail()
434
            ));
435
436
            $this->output->notice("Writing file: {file}", array('file' => $contentItem->getTargetFile()));
437
            $this->targetDir->writeFile($contentItem->getTargetFile(), $output);
438
        }
439
    }
440
441
    /**
442
     * @param PageView $pageView
443
     */
444
    private function compileStaticPageView (&$pageView)
445
    {
446
        $this->twig->addGlobal('__currentTemplate', $pageView->getFilePath());
447
448
        $template = $this->createTemplate($pageView);
449
        $output = $template->render(array(
450
            'this' => $pageView->createJail()
451
        ));
452
453
        $this->output->notice("Writing file: {file}", array('file' => $pageView->getTargetFile()));
454
        $this->targetDir->writeFile($pageView->getTargetFile(), $output);
455
    }
456
457
    /**
458
     * @param DynamicPageView|PageView $pageView
459
     */
460
    private function compileNormalRedirects (&$pageView)
461
    {
462
        foreach ($pageView->getRedirects() as $redirect)
0 ignored issues
show
Bug introduced by
The expression $pageView->getRedirects() of type null|array<integer,string> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
463
        {
464
            $redirectPageView = PageView::createRedirect(
465
                $redirect,
466
                $pageView->getPermalink(),
467
                $this->redirectTemplate
468
            );
469
470
            $this->compilePageView($redirectPageView);
471
        }
472
    }
473
474
    /**
475
     * @param RepeaterPageView $pageView
476
     */
477
    private function compileExpandedRedirects (&$pageView)
478
    {
479
        $permalinks = $pageView->getRepeaterPermalinks();
480
481
        /** @var ExpandedValue[] $repeaterRedirect */
482
        foreach ($pageView->getRepeaterRedirects() as $repeaterRedirect)
483
        {
484
            /**
485
             * @var int           $index
486
             * @var ExpandedValue $redirect
487
             */
488
            foreach ($repeaterRedirect as $index => $redirect)
489
            {
490
                $redirectPageView = PageView::createRedirect(
491
                    $redirect->getEvaluated(),
492
                    $permalinks[$index]->getEvaluated(),
493
                    $this->redirectTemplate
494
                );
495
496
                $this->compilePageView($redirectPageView);
497
            }
498
        }
499
    }
500
501
    /**
502
     * Add a static PageView to the menu array. Dynamic PageViews are not added to the menu
503
     *
504
     * @param PageView $pageView
505
     */
506
    private function addToSiteMenu (&$pageView)
507
    {
508
        $frontMatter = $pageView->getFrontMatter();
509
510
        if (isset($frontMatter['menu']) && !$frontMatter['menu'])
511
        {
512
            return;
513
        }
514
515
        $url = trim($pageView->getPermalink(), '/');
516
517
        if (empty($url))
518
        {
519
            return;
520
        }
521
522
        $root = &$this->siteMenu;
523
        $dirs = explode('/', $url);
524
525
        while (count($dirs) > 0)
526
        {
527
            $name = array_shift($dirs);
528
            $name = (!empty($name)) ? $name : '.';
529
530
            if (!is_null($name) && count($dirs) == 0)
531
            {
532
                if (isset($root[$name]) && is_array($root[$name]))
533
                {
534
                    $children = &$pageView->getChildren();
535
                    $children = $root[$name]['children'];
536
                }
537
538
                $root[$name] = &$pageView;
539
            }
540
            else
541
            {
542
                if (!isset($root[$name]['children']))
543
                {
544
                    $root[$name]['children'] = array();
545
                }
546
547
                $root = &$root[$name]['children'];
548
            }
549
        }
550
    }
551
552
    /**
553
     * @param PageView $pageView
554
     *
555
     * @return Twig_Template
556
     * @throws Twig_Error_Syntax
557
     */
558
    private function createTemplate (&$pageView)
559
    {
560
        try
561
        {
562
            $template = $this->twig->createTemplate($pageView->getContent());
563
564
            $this->trackParentTwigTemplate($template, $pageView);
565
566
            return $template;
567
        }
568
        catch (Twig_Error_Syntax $e)
569
        {
570
            $e->setTemplateLine($e->getTemplateLine() + $pageView->getLineOffset());
571
            $e->setTemplateName($pageView->getRelativeFilePath());
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Error::setTemplateName() has been deprecated with message: since 1.29 (to be removed in 2.0). Use setSourceContext() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
572
573
            throw $e;
574
        }
575
    }
576
577
    /**
578
     * Find the parent Twig templates of the given template and keep a list of it
579
     *
580
     * @param Twig_Template $template The template created from the PageView's content
581
     * @param PageView      $pageView The PageView that has this content. Used to keep a reference of PageViews
582
     */
583
    private function trackParentTwigTemplate ($template, &$pageView)
584
    {
585
        if (!$this->tracking) { return; }
586
587
        /** @var Twig_Template $parent */
588
        $parent = $template->getParent(array());
589
590
        while ($parent !== false)
591
        {
592
            $filePath = $this->fs->getRelativePath($parent->getSourceContext()->getPath());
593
594
            $this->twigExtendsDeps[$filePath][(string)$pageView->getFilePath()] = &$pageView;
595
            $parent = $parent->getParent(array());
596
        }
597
    }
598
}