فهرست منبع

Fix sessionHander->read() return type

walkor 2 سال پیش
والد
کامیت
586a517c5b

+ 4 - 4
src/Protocols/Http/Session/FileSessionHandler.php

@@ -88,19 +88,19 @@ class FileSessionHandler implements SessionHandlerInterface
     /**
      * {@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;
     }
 
     /**

+ 1 - 1
src/Protocols/Http/Session/RedisClusterSessionHandler.php

@@ -48,7 +48,7 @@ class RedisClusterSessionHandler extends RedisSessionHandler
     /**
      * {@inheritdoc}
      */
-    public function read(string $sessionId): string
+    public function read(string $sessionId): string|false
     {
         return $this->redis->get($sessionId);
     }

+ 2 - 2
src/Protocols/Http/Session/RedisSessionHandler.php

@@ -102,11 +102,11 @@ class RedisSessionHandler implements SessionHandlerInterface
     /**
      * {@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);

+ 3 - 3
src/Protocols/Http/Session/SessionHandlerInterface.php

@@ -74,14 +74,14 @@ interface SessionHandlerInterface
      * 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