mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 16:54:44 +02:00
Update Session API var to add a $session->sessionHandler() method that returns an instance to the current WireSessionHandler instance, or null if using PHP file-based sessions.
This commit is contained in:
@@ -119,6 +119,14 @@ class Session extends Wire implements \IteratorAggregate {
|
|||||||
*/
|
*/
|
||||||
protected $sessionAllow = null;
|
protected $sessionAllow = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instance of custom session handler module, when in use (null when not)
|
||||||
|
*
|
||||||
|
* @var WireSessionHandler|null
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $sessionHandler = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of key/index within $_SESSION where PW keeps its session data
|
* Name of key/index within $_SESSION where PW keeps its session data
|
||||||
*
|
*
|
||||||
@@ -1486,5 +1494,22 @@ class Session extends Wire implements \IteratorAggregate {
|
|||||||
if(is_null($this->CSRF)) $this->CSRF = $this->wire(new SessionCSRF());
|
if(is_null($this->CSRF)) $this->CSRF = $this->wire(new SessionCSRF());
|
||||||
return $this->CSRF;
|
return $this->CSRF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get or set current session handler instance (WireSessionHandler)
|
||||||
|
*
|
||||||
|
* #pw-internal
|
||||||
|
*
|
||||||
|
* @param WireSessionHandler|null $sessionHandler Specify only when setting, omit to get session handler.
|
||||||
|
* @return null|WireSessionHandler Returns WireSessionHandler instance, or…
|
||||||
|
* returns null when session handler is not yet known or is PHP (file system)
|
||||||
|
* @since 3.0.166
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function sessionHandler(WireSessionHandler $sessionHandler = null) {
|
||||||
|
if($sessionHandler) $this->sessionHandler = $sessionHandler;
|
||||||
|
return $this->sessionHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@ abstract class WireSessionHandler extends WireData implements Module {
|
|||||||
*/
|
*/
|
||||||
public function wired() {
|
public function wired() {
|
||||||
if(!$this->sessionExists()) {
|
if(!$this->sessionExists()) {
|
||||||
$this->addHookBefore('Session::init', $this, 'attach');
|
$this->addHookBefore('Session::init', $this, 'hookSessionInit');
|
||||||
register_shutdown_function('session_write_close');
|
register_shutdown_function('session_write_close');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,18 @@ abstract class WireSessionHandler extends WireData implements Module {
|
|||||||
*/
|
*/
|
||||||
public function init() { }
|
public function init() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook before Session::init
|
||||||
|
*
|
||||||
|
* @param HookEvent $event
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function hookSessionInit(HookEvent $event) {
|
||||||
|
$session = $event->object; /** @var Session $session */
|
||||||
|
$this->attach();
|
||||||
|
$session->sessionHandler($this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach this as the session handler
|
* Attach this as the session handler
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user