|
|
@@ -17,7 +17,6 @@
|
|
|
namespace Cake\Network\Session;
|
|
|
|
|
|
use Cake\Cache\Cache;
|
|
|
-use Cake\Core\Configure;
|
|
|
use SessionHandlerInterface;
|
|
|
|
|
|
/**
|
|
|
@@ -28,6 +27,24 @@ use SessionHandlerInterface;
|
|
|
class CacheSession implements SessionHandlerInterface {
|
|
|
|
|
|
/**
|
|
|
+ * Options for this session engine
|
|
|
+ *
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ protected $_options = [];
|
|
|
+
|
|
|
+/**
|
|
|
+ * Constructor.
|
|
|
+ *
|
|
|
+ * @param array $config The configuration to use for this engine
|
|
|
+ * It requires the key 'config' which is the name of the Cache config to use for
|
|
|
+ * storign the session
|
|
|
+ */
|
|
|
+ public function __construct(array $config) {
|
|
|
+ $this->_options = $config;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
* Method called on open of a database session.
|
|
|
*
|
|
|
* @param string $savePath The path where to store/retrieve the session.
|
|
|
@@ -54,7 +71,7 @@ class CacheSession implements SessionHandlerInterface {
|
|
|
* @return mixed The value of the key or false if it does not exist
|
|
|
*/
|
|
|
public function read($id) {
|
|
|
- return Cache::read($id, Configure::read('Session.handler.config'));
|
|
|
+ return Cache::read($id, $this->_options['config']);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -65,7 +82,7 @@ class CacheSession implements SessionHandlerInterface {
|
|
|
* @return bool True for successful write, false otherwise.
|
|
|
*/
|
|
|
public function write($id, $data) {
|
|
|
- return Cache::write($id, $data, Configure::read('Session.handler.config'));
|
|
|
+ return Cache::write($id, $data, $this->_options['config']);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -75,7 +92,7 @@ class CacheSession implements SessionHandlerInterface {
|
|
|
* @return bool True for successful delete, false otherwise.
|
|
|
*/
|
|
|
public function destroy($id) {
|
|
|
- return Cache::delete($id, Configure::read('Session.handler.config'));
|
|
|
+ return Cache::delete($id, $this->_options['config']);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -85,7 +102,7 @@ class CacheSession implements SessionHandlerInterface {
|
|
|
* @return bool True on success, false on failure.
|
|
|
*/
|
|
|
public function gc($maxlifetime) {
|
|
|
- return Cache::gc(Configure::read('Session.handler.config'), time() - $maxlifetime);
|
|
|
+ return Cache::gc($this->_options['config'], time() - $maxlifetime);
|
|
|
}
|
|
|
|
|
|
}
|