Completed
Push — master ( 0b2e6b...2c86a7 )
by Paul
49:42 queued 39:17
created

CurrentViewHelper::getMainCurrentView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Victoire\Bundle\CoreBundle\Helper;
4
5
use Victoire\Bundle\CoreBundle\Entity\View;
6
7
/**
8
 * This Helper give you the current view (BasePage or Template)
9
 * ~ victoire_core.current_view.
10
 */
11
class CurrentViewHelper
12
{
13
    protected $currentView;
14
    protected $updatedCurrentView;
15
16
    /**
17
     * Get currentView.
18
     *
19
     * @return View
20
     */
21
    public function getCurrentView()
22
    {
23
        return $this->currentView;
24
    }
25
26
    /**
27
     * Get updatedCurrentView.
28
     *
29
     * @return View
30
     */
31
    public function getUpdatedCurrentView()
32
    {
33
        return $this->updatedCurrentView;
34
    }
35
36
    /**
37
     * Set currentView.
38
     *
39
     * @param View $currentView
40
     *
41
     * @return $this
42
     */
43
    public function setCurrentView(View $currentView)
44
    {
45
        if ($this->currentView == null) {
46
            $this->currentView = clone $currentView;
47
        }
48
        $this->updatedCurrentView = $currentView;
49
50
        return $this;
51
    }
52
53
    /**
54
     * This method allow you to get the current view using a Current View Helper as a method
55
     * ex.
56
     * $currentViewHelper = $this->get('victoire_core.current_view');
57
     * $currentView = $currentViewHelper();.
58
     *
59
     * @return View The current View
60
     */
61
    public function __invoke()
62
    {
63
        if ($this->currentView) {
64
            return $this->currentView;
65
        }
66
    }
67
}
68