Session.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Auth
  17. * @subpackage Storage
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Auth_Storage_Interface
  24. */
  25. require_once 'Zend/Auth/Storage/Interface.php';
  26. /**
  27. * @see Zend_Session
  28. */
  29. require_once 'Zend/Session.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Auth
  33. * @subpackage Storage
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Auth_Storage_Session implements Zend_Auth_Storage_Interface
  38. {
  39. /**
  40. * Default session namespace
  41. */
  42. const NAMESPACE_DEFAULT = 'Zend_Auth';
  43. /**
  44. * Default session object member name
  45. */
  46. const MEMBER_DEFAULT = 'storage';
  47. /**
  48. * Object to proxy $_SESSION storage
  49. *
  50. * @var Zend_Session_Namespace
  51. */
  52. protected $_session;
  53. /**
  54. * Session namespace
  55. *
  56. * @var mixed
  57. */
  58. protected $_namespace;
  59. /**
  60. * Session object member
  61. *
  62. * @var mixed
  63. */
  64. protected $_member;
  65. /**
  66. * Sets session storage options and initializes session namespace object
  67. *
  68. * @param mixed $namespace
  69. * @param mixed $member
  70. */
  71. public function __construct($namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT)
  72. {
  73. $this->_namespace = $namespace;
  74. $this->_member = $member;
  75. $this->_session = new Zend_Session_Namespace($this->_namespace);
  76. }
  77. /**
  78. * Returns the session namespace
  79. *
  80. * @return string
  81. */
  82. public function getNamespace()
  83. {
  84. return $this->_namespace;
  85. }
  86. /**
  87. * Returns the name of the session object member
  88. *
  89. * @return string
  90. */
  91. public function getMember()
  92. {
  93. return $this->_member;
  94. }
  95. /**
  96. * Defined by Zend_Auth_Storage_Interface
  97. *
  98. * @return boolean
  99. */
  100. public function isEmpty()
  101. {
  102. return !isset($this->_session->{$this->_member});
  103. }
  104. /**
  105. * Defined by Zend_Auth_Storage_Interface
  106. *
  107. * @return mixed
  108. */
  109. public function read()
  110. {
  111. return $this->_session->{$this->_member};
  112. }
  113. /**
  114. * Defined by Zend_Auth_Storage_Interface
  115. *
  116. * @param mixed $contents
  117. * @return void
  118. */
  119. public function write($contents)
  120. {
  121. $this->_session->{$this->_member} = $contents;
  122. }
  123. /**
  124. * Defined by Zend_Auth_Storage_Interface
  125. *
  126. * @return void
  127. */
  128. public function clear()
  129. {
  130. unset($this->_session->{$this->_member});
  131. }
  132. }