Skip to content

Commit

Permalink
Fix sessionHander->read() return type
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Nov 13, 2023
1 parent 0eea85b commit 586a517
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/Protocols/Http/Session/FileSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ public function open(string $savePath, string $name): bool
/**
* {@inheritdoc}
*/
public function read(string $sessionId): string
public function read(string $sessionId): string|false
{
$sessionFile = static::sessionFile($sessionId);
clearstatcache();
if (is_file($sessionFile)) {
if (time() - filemtime($sessionFile) > Session::$lifetime) {
unlink($sessionFile);
return '';
return false;
}
$data = file_get_contents($sessionFile);
return $data ?: '';
return $data ?: false;
}
return '';
return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Protocols/Http/Session/RedisClusterSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct($config)
/**
* {@inheritdoc}
*/
public function read(string $sessionId): string
public function read(string $sessionId): string|false
{
return $this->redis->get($sessionId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Protocols/Http/Session/RedisSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ public function open(string $savePath, string $name): bool
/**
* {@inheritdoc}
* @param string $sessionId
* @return string
* @return string|false
* @throws RedisException
* @throws Throwable
*/
public function read(string $sessionId): string
public function read(string $sessionId): string|false
{
try {
return $this->redis->get($sessionId);
Expand Down
6 changes: 3 additions & 3 deletions src/Protocols/Http/Session/SessionHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ public function open(string $savePath, string $name): bool;
* Read session data
* @link http://php.net/manual/en/sessionhandlerinterface.read.php
* @param string $sessionId The session id to read data for.
* @return string <p>
* @return string|false <p>
* Returns an encoded string of the read data.
* If nothing was read, it must return an empty string.
* If nothing was read, it must return false.
* Note this value is returned internally to PHP for processing.
* </p>
* @since 5.4.0
*/
public function read(string $sessionId): string;
public function read(string $sessionId): string|false;

/**
* Write session data
Expand Down

0 comments on commit 586a517

Please sign in to comment.