Skip to content

Commit f02d3f5

Browse files
authored
Fix #195: Use Instance::ensure() to initialize Session::$redis
1 parent 06ecc3d commit f02d3f5

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Yii Framework 2 redis extension Change Log
44
2.0.12 under development
55
------------------------
66

7-
- no changes in this release.
7+
- Enh #195: Use `Instance::ensure()` to initialize `Session::$redis` (rob006)
88

99

1010
2.0.11 November 05, 2019

src/Session.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Yii;
1111
use yii\base\InvalidConfigException;
12+
use yii\di\Instance;
1213

1314
/**
1415
* Redis Session implements a session component using [redis](http://redis.io/) as the storage medium.
@@ -79,17 +80,7 @@ class Session extends \yii\web\Session
7980
*/
8081
public function init()
8182
{
82-
if (is_string($this->redis)) {
83-
$this->redis = Yii::$app->get($this->redis);
84-
} elseif (is_array($this->redis)) {
85-
if (!isset($this->redis['class'])) {
86-
$this->redis['class'] = Connection::className();
87-
}
88-
$this->redis = Yii::createObject($this->redis);
89-
}
90-
if (!$this->redis instanceof Connection) {
91-
throw new InvalidConfigException("Session::redis must be either a Redis connection instance or the application component ID of a Redis connection.");
92-
}
83+
$this->redis = Instance::ensure($this->redis, Connection::className());
9384
if ($this->keyPrefix === null) {
9485
$this->keyPrefix = substr(md5(Yii::$app->id), 0, 5);
9586
}

0 commit comments

Comments
 (0)