Completed
Push — master ( b82aa8...9291f8 )
by Vladimir
02:16
created

RepeaterPageView::bumpPermalink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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 ExpandedValue[] All of the expanded permalinks. */
16
    private $permalinks;
17
18
    /** @var ExpandedValue[][] All of expanded redirects that should point to the respective permalink; this is estimated by index. */
19
    private $redirectLinks;
20
21
    /**
22
     * RepeaterPageView constructor.
23
     */
24 3
    public function __construct(File $file)
25
    {
26 3
        parent::__construct($file);
27
28 3
        $this->type = BasePageView::REPEATER_TYPE;
29 3
    }
30
31
    /**
32
     * Get the permalink matching all the placeholders for a Repeater.
33
     *
34
     * @param array $where
35
     *
36
     * @return null|string
37
     */
38
    public function _getPermalinkWhere(array $where)
39
    {
40
        foreach ($this->permalinks as $expandedValue)
41
        {
42
            if ($expandedValue->getIterators() === $where)
43
            {
44
                return $expandedValue->getEvaluated();
45
            }
46
        }
47
48
        return null;
49
    }
50
51
    /**
52
     * Get the expanded values for the permalinks to this PageView.
53
     *
54
     * @return ExpandedValue[]
55
     */
56 3
    public function getRepeaterPermalinks()
57
    {
58 3
        return $this->permalinks;
59
    }
60
61
    /**
62
     * Get the expanded values for the redirects pointing to this PageView.
63
     *
64
     * @return ExpandedValue[][]
65
     */
66 3
    public function getRepeaterRedirects()
67
    {
68 3
        return $this->redirectLinks;
69
    }
70
71
    /**
72
     * Configure permalinks from expanded values internally.
73
     */
74 3
    public function configurePermalinks()
75
    {
76 3
        $evaluated = $this->frontMatter['permalink'];
77
78 3
        $this->permalinks = $evaluated[0];
79 3
        array_shift($evaluated);
80 3
        $this->redirectLinks = $evaluated;
81 3
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function buildPermalink($force = false)
87
    {
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 3
    public function createJail()
94
    {
95 3
        $whitelist = array_merge(self::$whiteListedFunctions, [
96 3
            '_getPermalinkWhere',
97
        ]);
98
99 3
        return new JailedDocument($this, $whitelist);
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function jsonSerialize()
106
    {
107
        return [];
108
    }
109
}
110