Skip to content

Commit bc0f062

Browse files
Merge branch '5.4' into 6.0
* 5.4: (46 commits) move username/password fix to non-deprecated Connection class cs fix [VarDumper] Fix dumping twig templates found in exceptions do not replace definition arguments that have not been configured fix Console tests on Windows [Validator] Add translations for CIDR constraint [Dotenv] Fix testLoadEnv() to start from a fresh context [Console] Add completion to server:dump command bug #42194 [RateLimiter] fix: sliding window policy to use microtime [Validator] Update validators.sr_Cyrl.xlf [Validator] Update validators.sr_Latn.xlf Add suggestions for the option 'format' of lints commands: twig, yaml and xliff [VarDumper] Add support for Fiber uzb translation Update validators.uz.xlf Fix logging of impersonator introduced in 5.3 [Console] Add show proxified command class in completion debug skip command completion tests with older Symfony Console versions [Uid] Allow use autocompletion [Console] Add completion to messenger:setup-transports command ...
2 parents 6b86781 + 7230e37 commit bc0f062

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CHANGELOG
2525
* Deprecate passing `null` as `$requestIp` to `IpUtils::__checkIp()`, `IpUtils::__checkIp4()` or `IpUtils::__checkIp6()`, pass an empty string instead.
2626
* Add the `litespeed_finish_request` method to work with Litespeed
2727
* Deprecate `upload_progress.*` and `url_rewriter.tags` session options
28+
* Allow setting session options via DSN
2829

2930
5.3
3031
---

Session/Storage/Handler/MemcachedSessionHandler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ class MemcachedSessionHandler extends AbstractSessionHandler
3838
*
3939
* List of available options:
4040
* * prefix: The prefix to use for the memcached keys in order to avoid collision
41-
* * expiretime: The time to live in seconds.
41+
* * ttl: The time to live in seconds.
4242
*
4343
* @throws \InvalidArgumentException When unsupported options are passed
4444
*/
4545
public function __construct(\Memcached $memcached, array $options = [])
4646
{
4747
$this->memcached = $memcached;
4848

49-
if ($diff = array_diff(array_keys($options), ['prefix', 'expiretime'])) {
49+
if ($diff = array_diff(array_keys($options), ['prefix', 'expiretime', 'ttl'])) {
5050
throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff)));
5151
}
5252

53-
$this->ttl = isset($options['expiretime']) ? (int) $options['expiretime'] : 86400;
53+
$this->ttl = $options['expiretime'] ?? $options['ttl'] ?? null;
5454
$this->prefix = $options['prefix'] ?? 'sf2s';
5555
}
5656

@@ -69,7 +69,7 @@ protected function doRead(string $sessionId): string
6969

7070
public function updateTimestamp(string $sessionId, string $data): bool
7171
{
72-
$this->memcached->touch($this->prefix.$sessionId, time() + $this->ttl);
72+
$this->memcached->touch($this->prefix.$sessionId, time() + (int) ($this->ttl ?? ini_get('session.gc_maxlifetime')));
7373

7474
return true;
7575
}
@@ -79,7 +79,7 @@ public function updateTimestamp(string $sessionId, string $data): bool
7979
*/
8080
protected function doWrite(string $sessionId, string $data): bool
8181
{
82-
return $this->memcached->set($this->prefix.$sessionId, $data, time() + $this->ttl);
82+
return $this->memcached->set($this->prefix.$sessionId, $data, time() + (int) ($this->ttl ?? ini_get('session.gc_maxlifetime')));
8383
}
8484

8585
/**

Session/Storage/Handler/SessionHandlerFactory.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class SessionHandlerFactory
2323
{
2424
public static function createHandler(object|string $connection): AbstractSessionHandler
2525
{
26+
if (\is_string($connection) && $options = parse_url($connection)) {
27+
parse_str($options['query'] ?? '', $options);
28+
} else {
29+
$options = [];
30+
}
31+
2632
switch (true) {
2733
case $connection instanceof \Redis:
2834
case $connection instanceof \RedisArray:
@@ -54,7 +60,7 @@ public static function createHandler(object|string $connection): AbstractSession
5460
$handlerClass = str_starts_with($connection, 'memcached:') ? MemcachedSessionHandler::class : RedisSessionHandler::class;
5561
$connection = AbstractAdapter::createConnection($connection, ['lazy' => true]);
5662

57-
return new $handlerClass($connection);
63+
return new $handlerClass($connection, array_intersect_key($options, ['prefix' => 1, 'ttl' => 1]));
5864

5965
case str_starts_with($connection, 'pdo_oci://'):
6066
if (!class_exists(DriverManager::class)) {
@@ -72,7 +78,7 @@ public static function createHandler(object|string $connection): AbstractSession
7278
case str_starts_with($connection, 'sqlsrv://'):
7379
case str_starts_with($connection, 'sqlite://'):
7480
case str_starts_with($connection, 'sqlite3://'):
75-
return new PdoSessionHandler($connection);
81+
return new PdoSessionHandler($connection, $options ?: []);
7682
}
7783

7884
throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection));

0 commit comments

Comments
 (0)