SessionHelper.php 2.3 KB

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