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.0/en/views/helpers/session.html
26: * @deprecated 3.0.2 Use request->session() instead.
27: */
28: class SessionHelper extends Helper
29: {
30:
31: /**
32: * Constructor
33: *
34: * @param \Cake\View\View $View The View this helper is being attached to.
35: * @param array $config Configuration settings for the helper.
36: */
37: public function __construct(View $View, array $config = [])
38: {
39: deprecationWarning(
40: 'SessionHelper is deprecated and will be removed in 4.0.0. ' .
41: 'Use request->session() instead.'
42: );
43:
44: parent::__construct($View, $config);
45: }
46:
47: /**
48: * Reads a session value for a key or returns values for all keys.
49: *
50: * In your view:
51: * ```
52: * $this->Session->read('Controller.sessKey');
53: * ```
54: * Calling the method without a param will return all session vars
55: *
56: * @param string|null $name The name of the session key you want to read
57: * @return mixed Values from the session vars
58: */
59: public function read($name = null)
60: {
61: return $this->_View->getRequest()->getSession()->read($name);
62: }
63:
64: /**
65: * Checks if a session key has been set.
66: *
67: * In your view:
68: * ```
69: * $this->Session->check('Controller.sessKey');
70: * ```
71: *
72: * @param string $name Session key to check.
73: * @return bool
74: */
75: public function check($name)
76: {
77: return $this->_View->getRequest()->getSession()->check($name);
78: }
79:
80: /**
81: * Event listeners.
82: *
83: * @return array
84: */
85: public function implementedEvents()
86: {
87: return [];
88: }
89: }
90: