Source of file HybridSession.php
Size: 3,140 Bytes - Last Modified: 2021-12-23T10:32:34+00:00
/var/www/docs.ssmods.com/process/src/src/HybridSession.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 | <?php namespace SilverStripe\HybridSessions; use SessionHandlerInterface; use SilverStripe\Core\Injector\Injector; use SilverStripe\HybridSessions\Store\BaseStore; class HybridSession extends BaseStore { /** * List of session handlers * * @var array */ protected $handlers = []; /** * True if this session store has been initialised * * @var bool */ protected static $enabled = false; /** * @param SessionHandlerInterface[] * * @return $this */ public function setHandlers($handlers) { $this->handlers = $handlers; $this->setKey($this->getKey()); return $this; } /** * @param string * * @return $this */ public function setKey($key) { parent::setKey($key); foreach ($this->getHandlers() as $handler) { $handler->setKey($key); } return $this; } /** * @return SessionHandlerInterface[] */ public function getHandlers() { return $this->handlers ?: []; } /** * @param string $save_path * @param string $name * * @return bool */ public function open($save_path, $name) { foreach ($this->getHandlers() as $handler) { $handler->open($save_path, $name); } return true; } /** * @return bool */ public function close() { foreach ($this->getHandlers() as $handler) { $handler->close(); } return true; } /** * @param string $session_id * * @return string */ public function read($session_id) { foreach ($this->getHandlers() as $handler) { if ($data = $handler->read($session_id)) { return $data; } } return ''; } public function write($session_id, $session_data) { foreach ($this->getHandlers() as $handler) { if ($handler->write($session_id, $session_data)) { return true; } } return false; } public function destroy($session_id) { foreach ($this->getHandlers() as $handler) { $handler->destroy($session_id); } return true; } public function gc($maxlifetime) { foreach ($this->getHandlers() as $handler) { $handler->gc($maxlifetime); } } /** * Register the session handler as the default * * @param string $key Desired session key */ public static function init($key = null) { $instance = Injector::inst()->get(__CLASS__); if (empty($key)) { user_error( 'HybridSession::init() was not given a $key. Disabling cookie-based storage', E_USER_WARNING ); } else { $instance->setKey($key); } session_set_save_handler($instance, true); self::$enabled = true; } public static function is_enabled() { return self::$enabled; } } |