Completed
Push — master ( 5ea837...9dec3c )
by Paul
9s
created

SessionHelper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 87
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 1
A getFlash() 0 4 1
A getFlashes() 0 4 1
A hasFlash() 0 4 1
A hasFlashes() 0 4 1
A getName() 0 4 1
1
<?php
2
/**
3
 * This file is part of the PPI Framework.
4
 *
5
 * @copyright  Copyright (c) 2011-2016 Paul Dragoonis <[email protected]>
6
 * @license    http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 * @link       http://www.ppi.io
9
 */
10
11
namespace PPI\Framework\View\Helper;
12
13
use Symfony\Component\HttpFoundation\Session\SessionInterface;
14
use Symfony\Component\Templating\Helper\Helper;
15
16
/**
17
 * SessionHelper provides read-only access to the session attributes.
18
 *
19
 * @author     Fabien Potencier <[email protected]>
20
 * @author     Paul Dragoonis <[email protected]>
21
 */
22
class SessionHelper extends Helper
23
{
24
    /**
25
     * @todo Add inline documentation.
26
     *
27
     * @var SessionInterface
28
     */
29
    protected $session;
30
31
    /**
32
     * Constructor.
33
     *
34
     * @param SessionInterface $session
35
     */
36
    public function __construct(SessionInterface $session)
37
    {
38
        $this->session = $session;
39
    }
40
41
    /**
42
     * Returns an attribute.
43
     *
44
     * @param string $name    The attribute name
45
     * @param mixed  $default The default value
46
     *
47
     * @return mixed
48
     */
49
    public function get($name, $default = null)
50
    {
51
        return $this->session->get($name, $default);
52
    }
53
54
    /**
55
     * @todo Add inline documentation.
56
     *
57
     * @param type  $name
58
     * @param array $default
59
     *
60
     * @return type
61
     */
62
    public function getFlash($name, array $default = array())
63
    {
64
        return $this->session->getFlashBag()->get($name, $default);
65
    }
66
67
    /**
68
     * @todo Add inline documentation.
69
     *
70
     * @return type
71
     */
72
    public function getFlashes()
73
    {
74
        return $this->session->getFlashBag()->all();
75
    }
76
77
    /**
78
     * @todo Add inline documentation.
79
     *
80
     * @param type $name
81
     *
82
     * @return type
83
     */
84
    public function hasFlash($name)
85
    {
86
        return $this->session->getFlashBag()->has($name);
87
    }
88
89
    /**
90
     * @todo Add inline documentation.
91
     *
92
     * @return type
93
     */
94
    public function hasFlashes()
95
    {
96
        return count($this->session->getFlashBag()->peekAll()) > 0;
97
    }
98
99
    /**
100
     * @todo Add inline documentation.
101
     *
102
     * @return string
103
     */
104
    public function getName()
105
    {
106
        return 'session';
107
    }
108
}
109