Session.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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-2014 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-2014 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. * @return void
  71. */
  72. public function __construct($namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT)
  73. {
  74. $this->_namespace = $namespace;
  75. $this->_member = $member;
  76. $this->_session = new Zend_Session_Namespace($this->_namespace);
  77. }
  78. /**
  79. * Returns the session namespace
  80. *
  81. * @return string
  82. */
  83. public function getNamespace()
  84. {
  85. return $this->_namespace;
  86. }
  87. /**
  88. * Returns the name of the session object member
  89. *
  90. * @return string
  91. */
  92. public function getMember()
  93. {
  94. return $this->_member;
  95. }
  96. /**
  97. * Defined by Zend_Auth_Storage_Interface
  98. *
  99. * @return boolean
  100. */
  101. public function isEmpty()
  102. {
  103. return !isset($this->_session->{$this->_member});
  104. }
  105. /**
  106. * Defined by Zend_Auth_Storage_Interface
  107. *
  108. * @return mixed
  109. */
  110. public function read()
  111. {
  112. return $this->_session->{$this->_member};
  113. }
  114. /**
  115. * Defined by Zend_Auth_Storage_Interface
  116. *
  117. * @param mixed $contents
  118. * @return void
  119. */
  120. public function write($contents)
  121. {
  122. $this->_session->{$this->_member} = $contents;
  123. }
  124. /**
  125. * Defined by Zend_Auth_Storage_Interface
  126. *
  127. * @return void
  128. */
  129. public function clear()
  130. {
  131. unset($this->_session->{$this->_member});
  132. }
  133. }