@@ -102,20 +102,21 @@ protected function setSavePath(): void
102102 throw SessionException::forEmptySavepath ();
103103 }
104104
105- if (preg_match ('#(?:tcp ://)?([^:?]+)(?:\:(\d+))?(\?.+)?# ' , $ this ->savePath , $ matches )) {
106- if (! isset ($ matches [3 ])) {
107- $ matches [3 ] = '' ; // Just to avoid undefined index notices below
105+ if (preg_match ('#(?:(^.*) ://)?([^:?]+)(?:\:(\d+))?(\?.+)?# ' , $ this ->savePath , $ matches )) {
106+ if (! isset ($ matches [4 ])) {
107+ $ matches [4 ] = '' ; // Just to avoid undefined index notices below
108108 }
109109
110110 $ this ->savePath = [
111- 'host ' => $ matches [1 ],
112- 'port ' => empty ($ matches [2 ]) ? self ::DEFAULT_PORT : $ matches [2 ],
113- 'password ' => preg_match ('#auth=([^\s&]+)# ' , $ matches [3 ], $ match ) ? $ match [1 ] : null ,
114- 'database ' => preg_match ('#database=(\d+)# ' , $ matches [3 ], $ match ) ? (int ) $ match [1 ] : 0 ,
115- 'timeout ' => preg_match ('#timeout=(\d+\.\d+|\d+)# ' , $ matches [3 ], $ match ) ? (float ) $ match [1 ] : 0.0 ,
111+ 'protocol ' => in_array ($ matches [1 ], ['tcp ' , 'tls ' ], true ) ? $ matches [1 ] : 'tcp ' ,
112+ 'host ' => $ matches [2 ],
113+ 'port ' => empty ($ matches [3 ]) ? self ::DEFAULT_PORT : $ matches [3 ],
114+ 'password ' => preg_match ('#auth=([^\s&]+)# ' , $ matches [4 ], $ match ) ? $ match [1 ] : null ,
115+ 'database ' => preg_match ('#database=(\d+)# ' , $ matches [4 ], $ match ) ? (int ) $ match [1 ] : 0 ,
116+ 'timeout ' => preg_match ('#timeout=(\d+\.\d+|\d+)# ' , $ matches [4 ], $ match ) ? (float ) $ match [1 ] : 0.0 ,
116117 ];
117118
118- preg_match ('#prefix=([^\s&]+)# ' , $ matches [3 ], $ match ) && $ this ->keyPrefix = $ match [1 ];
119+ preg_match ('#prefix=([^\s&]+)# ' , $ matches [4 ], $ match ) && $ this ->keyPrefix = $ match [1 ];
119120 } else {
120121 throw SessionException::forInvalidSavePathFormat ($ this ->savePath );
121122 }
@@ -135,7 +136,7 @@ public function open($path, $name): bool
135136
136137 $ redis = new Redis ();
137138
138- if (! $ redis ->connect ($ this ->savePath ['host ' ], ($ this ->savePath ['host ' ][0 ] === '/ ' ? 0 : $ this ->savePath ['port ' ]), $ this ->savePath ['timeout ' ])) {
139+ if (! $ redis ->connect ($ this ->savePath ['protocol ' ] . ' :// ' . $ this -> savePath [ ' host ' ], ($ this ->savePath ['host ' ][0 ] === '/ ' ? 0 : $ this ->savePath ['port ' ]), $ this ->savePath ['timeout ' ])) {
139140 $ this ->logger ->error ('Session: Unable to connect to Redis with the configured settings. ' );
140141 } elseif (isset ($ this ->savePath ['password ' ]) && ! $ redis ->auth ($ this ->savePath ['password ' ])) {
141142 $ this ->logger ->error ('Session: Unable to authenticate to Redis instance. ' );
0 commit comments