Completed
Pull Request — master (#78)
by Vladimir
04:42 queued 01:10
created

appendCustomVariables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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\Event;
9
10
use Symfony\Component\EventDispatcher\Event;
11
12
/**
13
 * This event is fired before a PageView is rendered and allows you inject custom variables into the templates.
14
 *
15
 * @since 0.2.0
16
 */
17
class CompileProcessPreRenderPageView extends Event
18
{
19
    const NAME = 'compile.process.prerender_pageview';
20
21
    private $customVariables = [];
22
    private $pageViewType;
23
24 12
    public function __construct($pageViewType)
25
    {
26 12
        $this->pageViewType = $pageViewType;
27 12
    }
28
29
    public function getPageViewType()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
30
    {
31
        return $this->pageViewType;
32
    }
33
34 12
    public function getCustomVariables()
35
    {
36 12
        if (!is_array($this->customVariables))
37
        {
38
            return [];
39
        }
40
41 12
        return $this->customVariables;
42
    }
43
44
    /**
45
     * Append custom variables that'll be made available as template variables in PageViews.
46
     *
47
     * @param array $customVariables
48
     *
49
     * @since 0.2.0
50
     */
51
    public function appendCustomVariables(array $customVariables)
52
    {
53
        $this->customVariables = array_merge($this->customVariables, $customVariables);
54
    }
55
}
56