Commit 7e1e6224 by John Was

simpler implementation of the handler property in yii\web\Session

parent 53bb2594
......@@ -47,7 +47,6 @@ use yii\base\InvalidParamException;
*
* @property array $allFlashes Flash messages (key => message). This property is read-only.
* @property array $cookieParams The session cookie parameters. This property is read-only.
* @property SessionHandlerInterface $handler an object providing persistance methods implementation.
* @property integer $count The number of session variables. This property is read-only.
* @property string $flash The key identifying the flash message. Note that flash messages and normal session
* variables share the same name space. If you have a normal session variable using the same name, its value will
......@@ -82,15 +81,15 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
*/
public $flashVar = '__flash';
/**
* @var \SessionHandlerInterface|array an object implementing the SessionHandlerInterface or a configuration array. If set, will be used to provide persistency instead of build-in methods.
*/
public $handler;
/**
* @var array parameter-value pairs to override default session cookie parameters that are used for session_set_cookie_params() function
* Array may have the following possible keys: 'lifetime', 'path', 'domain', 'secure', 'httpOnly'
* @see http://www.php.net/manual/en/function.session-set-cookie-params.php
*/
private $_cookieParams = ['httpOnly' => true];
/**
* @var \SessionHandlerInterface|array an object implementing the SessionHandlerInterface or a configuration array. If set, will be used to provide persistency instead of build-in methods.
*/
private $_handler;
/**
* Initializes the application component.
......@@ -118,27 +117,6 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
}
/**
* @param array|\SessionHandlerInterface $handler handler instance or its array configuration, it will be used to
* provide persistance method implementations.
* @throws InvalidConfigException on invalid argument.
*/
public function setHandler($handler)
{
$this->_handler = is_object($handler) ? $handler : Yii::createObject($this->_handler);
if (!$this->handler instanceof \SessionHandlerInterface) {
throw new InvalidConfigException('"' . get_class($this) . '::handler" must implement the SessionHandlerInterface.');
}
}
/**
* @return SessionHandlerInterface handler instance.
*/
public function getHandler()
{
return $this->_handler;
}
/**
* Starts the session.
*/
public function open()
......@@ -147,8 +125,14 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
return;
}
if ($this->getHandler() !== null) {
@session_set_save_handler($this->getHandler(), false);
if ($this->handler !== null) {
if (!is_object($this->handler)) {
$this->handler = Yii::createObject($this->handler);
}
if (!$this->handler instanceof \SessionHandlerInterface) {
throw new InvalidConfigException('"' . get_class($this) . '::handler" must implement the SessionHandlerInterface.');
}
@session_set_save_handler($this->handler, false);
} elseif ($this->getUseCustomStorage()) {
@session_set_save_handler(
[$this, 'openSession'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment