Completed
Pull Request — master (#61)
by Vladimir
02:52
created

RepeaterPageView::getRepeaterRedirects()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/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 expanded values for the permalinks to this PageView.
36
     *
37
     * @return ExpandedValue[]
38
     */
39
    public function getRepeaterPermalinks()
40
    {
41
        return $this->permalinks;
42
    }
43
44
    /**
45
     * Get the expanded values for the redirects pointing to this PageView.
46
     *
47
     * @return ExpandedValue[][]
48
     */
49
    public function getRepeaterRedirects()
50
    {
51
        return $this->redirectLinks;
52
    }
53
54
    /**
55
     * When looping through permalinks in a RepeaterPageView, the permalink needs to be updated each time so that it may
56
     * behave as a static PageView.
57
     */
58
    public function bumpPermalink()
59
    {
60
        $this->permalink = $this->permalinksIterator->current()->getEvaluated();
61
        $this->permalinksIterator->next();
62
    }
63
64
    /**
65
     * Rewind the permalink iterator to the beginning.
66
     */
67
    public function rewindPermalink()
68
    {
69
        $this->permalinksIterator->rewind();
70
    }
71
72
    /**
73
     * Configure permalinks from expanded values internally.
74
     */
75 3
    public function configurePermalinks()
76
    {
77 3
        $evaluated = $this->frontMatter['permalink'];
78
79 3
        $this->permalinks = $evaluated[0];
80 3
        array_shift($evaluated);
81 3
        $this->redirectLinks = $evaluated;
82
83 3
        $this->permalinksIterator = new \ArrayIterator($this->permalinks);
84 3
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function buildPermalink($force = false)
90
    {
91
        return;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function createJail()
98
    {
99
        return (new JailedDocument($this, self::$whiteListedFunctions));
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function jsonSerialize()
106
    {
107
        return [];
108
    }
109
}
110