bug #34967 [HttpFoundation] fix redis multi host dsn not recognized (Jan Christoph Beyer)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpFoundation] fix redis multi host dsn not recognized

| Q             | A
| ------------- | ---
| Branch?       |  4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34477
| License       | MIT

#34177 added support configurating session handlers with DSNs. It was no possible to pass a redis-DSN like
`redis:?host[localhost]&host[localhost:6379]&host[/var/run/redis.sock:]&auth=my-password&redis_cluster=1'`

since the check was
`case 0 === strpos($connection, 'redis://'):`

Commits
-------

81ba07aa26 fix redis multi host dsn not recognized
This commit is contained in:
Nicolas Grekas 2019-12-13 12:54:36 +01:00
commit 212dc53431

View File

@ -50,13 +50,13 @@ class SessionHandlerFactory
case 0 === strpos($connection, 'file://'):
return new StrictSessionHandler(new NativeFileSessionHandler(substr($connection, 7)));
case 0 === strpos($connection, 'redis://'):
case 0 === strpos($connection, 'rediss://'):
case 0 === strpos($connection, 'memcached://'):
case 0 === strpos($connection, 'redis:'):
case 0 === strpos($connection, 'rediss:'):
case 0 === strpos($connection, 'memcached:'):
if (!class_exists(AbstractAdapter::class)) {
throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection));
}
$handlerClass = 0 === strpos($connection, 'memcached://') ? MemcachedSessionHandler::class : RedisSessionHandler::class;
$handlerClass = 0 === strpos($connection, 'memcached:') ? MemcachedSessionHandler::class : RedisSessionHandler::class;
$connection = AbstractAdapter::createConnection($connection, ['lazy' => true]);
return new $handlerClass($connection);