Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Server/Session/FileSessionStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function exists(Uuid $id): bool
return ($this->clock->now()->getTimestamp() - $mtime) <= $this->ttl;
}

public function read(Uuid $sessionId): string|false
public function read(Uuid $id): string|false
{
$path = $this->pathFor($sessionId);
$path = $this->pathFor($id);

if (!is_file($path)) {
return false;
Expand All @@ -73,9 +73,9 @@ public function read(Uuid $sessionId): string|false
return $data;
}

public function write(Uuid $sessionId, string $data): bool
public function write(Uuid $id, string $data): bool
{
$path = $this->pathFor($sessionId);
$path = $this->pathFor($id);

$tmp = $path.'.tmp';
if (false === @file_put_contents($tmp, $data, \LOCK_EX)) {
Expand All @@ -98,9 +98,9 @@ public function write(Uuid $sessionId, string $data): bool
return true;
}

public function destroy(Uuid $sessionId): bool
public function destroy(Uuid $id): bool
{
$path = $this->pathFor($sessionId);
$path = $this->pathFor($id);

if (is_file($path)) {
@unlink($path);
Expand Down
16 changes: 8 additions & 8 deletions src/Server/Session/InMemorySessionStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,38 @@ public function exists(Uuid $id): bool
return isset($this->store[$id->toRfc4122()]);
}

public function read(Uuid $sessionId): string|false
public function read(Uuid $id): string|false
{
$session = $this->store[$sessionId->toRfc4122()] ?? '';
$session = $this->store[$id->toRfc4122()] ?? '';
if ('' === $session) {
return false;
}

$currentTimestamp = $this->clock->now()->getTimestamp();

if ($currentTimestamp - $session['timestamp'] > $this->ttl) {
unset($this->store[$sessionId->toRfc4122()]);
unset($this->store[$id->toRfc4122()]);

return false;
}

return $session['data'];
}

public function write(Uuid $sessionId, string $data): bool
public function write(Uuid $id, string $data): bool
{
$this->store[$sessionId->toRfc4122()] = [
$this->store[$id->toRfc4122()] = [
'data' => $data,
'timestamp' => $this->clock->now()->getTimestamp(),
];

return true;
}

public function destroy(Uuid $sessionId): bool
public function destroy(Uuid $id): bool
{
if (isset($this->store[$sessionId->toRfc4122()])) {
unset($this->store[$sessionId->toRfc4122()]);
if (isset($this->store[$id->toRfc4122()])) {
unset($this->store[$id->toRfc4122()]);
}

return true;
Expand Down