Skip to content

Commit c56647f

Browse files
committed
Merge pull request yiisoft#1757 from nineinchnick/1476_session_handler
Add handler property to yii\web\Session
2 parents f2fb7de + 7e1e622 commit c56647f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: framework/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Yii Framework 2 Change Log
3636
- Enh #1406: DB Schema support for Oracle Database (p0larbeer, qiangxue)
3737
- Enh #1437: Added ListView::viewParams (qiangxue)
3838
- Enh #1469: ActiveRecord::find() now works with default conditions (default scope) applied by createQuery (cebe)
39+
- Enh #1476: Add yii\web\Session::handler property (nineinchnick)
3940
- Enh #1499: Added `ActionColumn::controller` property to support customizing the controller for handling GridView actions (qiangxue)
4041
- Enh #1523: Query conditions now allow to use the NOT operator (cebe)
4142
- Enh #1552: It is now possible to use multiple bootstrap NavBar in a single page (Alex-Code)

Diff for: framework/yii/web/Session.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
8080
* @var string the name of the session variable that stores the flash message data.
8181
*/
8282
public $flashVar = '__flash';
83+
/**
84+
* @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.
85+
*/
86+
public $handler;
8387
/**
8488
* @var array parameter-value pairs to override default session cookie parameters that are used for session_set_cookie_params() function
8589
* Array may have the following possible keys: 'lifetime', 'path', 'domain', 'secure', 'httpOnly'
@@ -121,7 +125,15 @@ public function open()
121125
return;
122126
}
123127

124-
if ($this->getUseCustomStorage()) {
128+
if ($this->handler !== null) {
129+
if (!is_object($this->handler)) {
130+
$this->handler = Yii::createObject($this->handler);
131+
}
132+
if (!$this->handler instanceof \SessionHandlerInterface) {
133+
throw new InvalidConfigException('"' . get_class($this) . '::handler" must implement the SessionHandlerInterface.');
134+
}
135+
@session_set_save_handler($this->handler, false);
136+
} elseif ($this->getUseCustomStorage()) {
125137
@session_set_save_handler(
126138
[$this, 'openSession'],
127139
[$this, 'closeSession'],

0 commit comments

Comments
 (0)