SessionHelper.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 1.1.7
  13. * @license http://www.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 http://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. trigger_error('SessionHelper has been deprecated. Use request->session() instead.', E_USER_DEPRECATED);
  37. parent::__construct($View, $config);
  38. }
  39. /**
  40. * Reads a session value for a key or returns values for all keys.
  41. *
  42. * In your view:
  43. * ```
  44. * $this->Session->read('Controller.sessKey');
  45. * ```
  46. * Calling the method without a param will return all session vars
  47. *
  48. * @param string|null $name The name of the session key you want to read
  49. * @return mixed Values from the session vars
  50. */
  51. public function read($name = null)
  52. {
  53. return $this->request->session()->read($name);
  54. }
  55. /**
  56. * Checks if a session key has been set.
  57. *
  58. * In your view:
  59. * ```
  60. * $this->Session->check('Controller.sessKey');
  61. * ```
  62. *
  63. * @param string $name Session key to check.
  64. * @return bool
  65. */
  66. public function check($name)
  67. {
  68. return $this->request->session()->check($name);
  69. }
  70. /**
  71. * Event listeners.
  72. *
  73. * @return array
  74. */
  75. public function implementedEvents()
  76. {
  77. return [];
  78. }
  79. }