SessionHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 61
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A read() 0 4 1
A check() 0 4 1
A implementedEvents() 0 4 1
1
<?php
2
/**
3
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11
 * @link          https://cakephp.org CakePHP(tm) Project
12
 * @since         1.1.7
13
 * @license       https://opensource.org/licenses/mit-license.php MIT License
14
 */
15
namespace Cake\View\Helper;
16
17
use Cake\View\Helper;
18
use Cake\View\View;
19
20
/**
21
 * Session Helper.
22
 *
23
 * Session reading from the view.
24
 *
25
 * @link https://book.cakephp.org/3/en/views/helpers/session.html
26
 * @deprecated 3.0.2 Use request->session() instead.
27
 */
28
class SessionHelper extends Helper
29
{
30
    /**
31
     * Constructor
32
     *
33
     * @param \Cake\View\View $View The View this helper is being attached to.
34
     * @param array $config Configuration settings for the helper.
35
     */
36
    public function __construct(View $View, array $config = [])
37
    {
38
        deprecationWarning(
39
            'SessionHelper is deprecated and will be removed in 4.0.0. ' .
40
            'Use request->session() instead.'
41
        );
42
43
        parent::__construct($View, $config);
44
    }
45
46
    /**
47
     * Reads a session value for a key or returns values for all keys.
48
     *
49
     * In your view:
50
     * ```
51
     * $this->Session->read('Controller.sessKey');
52
     * ```
53
     * Calling the method without a param will return all session vars
54
     *
55
     * @param string|null $name The name of the session key you want to read
56
     * @return mixed Values from the session vars
57
     */
58
    public function read($name = null)
59
    {
60
        return $this->_View->getRequest()->getSession()->read($name);
61
    }
62
63
    /**
64
     * Checks if a session key has been set.
65
     *
66
     * In your view:
67
     * ```
68
     * $this->Session->check('Controller.sessKey');
69
     * ```
70
     *
71
     * @param string $name Session key to check.
72
     * @return bool
73
     */
74
    public function check($name)
75
    {
76
        return $this->_View->getRequest()->getSession()->check($name);
77
    }
78
79
    /**
80
     * Event listeners.
81
     *
82
     * @return array
83
     */
84
    public function implementedEvents()
85
    {
86
        return [];
87
    }
88
}
89