Skip to content

Commit

Permalink
Merge branch '6.1' into 6.2
Browse files Browse the repository at this point in the history
* 6.1:
  [Mailer] Include all transports' debug messages in RoundRobin transport exception
  [FrameworkBundle] fix: fix help message
  Fix HtmlSanitizer default configuration behavior for allowed schemes
  Use relative timestamps
  [Cache] Fix dealing with ext-redis' multi/exec returning a bool
  [Messenger][Amqp] Added missing rpc_timeout option
  [Serializer] Prevent GetSetMethodNormalizer from creating invalid magic method call
  [HttpFoundation] Fix dumping array cookies
  [WebProfilerBundle] Fix dump header not being displayed
  TraceableHttpClient: increase decorator's priority
  Use static methods inside data providers
  [FrameworkBundle] Allow configuring `framework.exceptions` with a config builder
  bug #48313 [Mime] Fix MessagePart serialization
  [HttpKernel][ErrorHandler] Fix reading the SYMFONY_IDE env var
  [ErrorHandler][DebugClassLoader] Fix some new return types support
  Fix getting the name of closures on PHP 8.1.11+
  [Translator] Fix typo "internal" / "interval"
  fix dumping top-level tagged values
  [Console] Fix clear line with question in section
  • Loading branch information
nicolas-grekas committed Dec 14, 2022
2 parents b30304b + 2046d8c commit ddf4dd3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public function __toString(): string
$cookies = [];

foreach ($this->cookies as $k => $v) {
$cookies[] = $k.'='.$v;
$cookies[] = \is_array($v) ? http_build_query([$k => $v], '', '; ', \PHP_QUERY_RFC3986) : "$k=$v";
}

if ($cookies) {
Expand Down
16 changes: 13 additions & 3 deletions Session/Storage/Handler/MemcachedSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,27 @@ protected function doRead(string $sessionId): string

public function updateTimestamp(string $sessionId, string $data): bool
{
$ttl = ($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime');
$this->memcached->touch($this->prefix.$sessionId, time() + (int) $ttl);
$this->memcached->touch($this->prefix.$sessionId, $this->getCompatibleTtl());

return true;
}

protected function doWrite(string $sessionId, string $data): bool
{
return $this->memcached->set($this->prefix.$sessionId, $data, $this->getCompatibleTtl());
}

private function getCompatibleTtl(): int
{
$ttl = ($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime');

return $this->memcached->set($this->prefix.$sessionId, $data, time() + (int) $ttl);
// If the relative TTL that is used exceeds 30 days, memcached will treat the value as Unix time.
// We have to convert it to an absolute Unix time at this point, to make sure the TTL is correct.
if ($ttl > 60 * 60 * 24 * 30) {
$ttl += time();
}

return $ttl;
}

protected function doDestroy(string $sessionId): bool
Expand Down
6 changes: 6 additions & 0 deletions Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,12 @@ public function testToString()
$asString = (string) $request;

$this->assertStringContainsString('Cookie: Foo=Bar; Another=Cookie', $asString);

$request->cookies->set('foo.bar', [1, 2]);

$asString = (string) $request;

$this->assertStringContainsString('foo.bar%5B0%5D=1; foo.bar%5B1%5D=2', $asString);
}

public function testIsMethod()
Expand Down
20 changes: 19 additions & 1 deletion Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* @requires extension memcached
*
* @group time-sensitive
*/
class MemcachedSessionHandlerTest extends TestCase
Expand Down Expand Up @@ -92,13 +93,30 @@ public function testWriteSession()
$this->memcached
->expects($this->once())
->method('set')
->with(self::PREFIX.'id', 'data', $this->equalTo(time() + self::TTL, 2))
->with(self::PREFIX.'id', 'data', $this->equalTo(self::TTL, 2))
->willReturn(true)
;

$this->assertTrue($this->storage->write('id', 'data'));
}

public function testWriteSessionWithLargeTTL()
{
$this->memcached
->expects($this->once())
->method('set')
->with(self::PREFIX.'id', 'data', $this->equalTo(time() + self::TTL + 60 * 60 * 24 * 30, 2))
->willReturn(true)
;

$storage = new MemcachedSessionHandler(
$this->memcached,
['prefix' => self::PREFIX, 'expiretime' => self::TTL + 60 * 60 * 24 * 30]
);

$this->assertTrue($storage->write('id', 'data'));
}

public function testDestroySession()
{
$this->memcached
Expand Down

0 comments on commit ddf4dd3

Please sign in to comment.