Răsfoiți Sursa

Fix session handler warnings

Alan Lam 2 ani în urmă
părinte
comite
8065e6db64
1 a modificat fișierele cu 12 adăugiri și 14 ștergeri
  1. 12 14
      engine/site_session_handler.php

+ 12 - 14
engine/site_session_handler.php

@@ -2,7 +2,7 @@
 
 class SiteSessionHandler implements SessionHandlerInterface {
 
-	public function open($path, $name) {
+	public function open($path, $name): bool {
 		return true;
 	}
 
@@ -11,9 +11,9 @@ class SiteSessionHandler implements SessionHandlerInterface {
 	 * @return string
 	 * @throws Exception
 	 */
-	public function read($id) {
+	public function read($id): string {
 		$session = Session::get($id);
-		return $session ? $session->data : "";
+		return $session->data ?? "";
 	}
 
 	/**
@@ -22,8 +22,7 @@ class SiteSessionHandler implements SessionHandlerInterface {
 	 * @return bool
 	 * @throws Exception
 	 */
-	public function write($id, $data) {
-
+	public function write($id, $data): bool {
 		$session = Session::get($id);
 		if(!$session) {
 			$session = new Session;
@@ -35,7 +34,7 @@ class SiteSessionHandler implements SessionHandlerInterface {
 		return $session->commit();
 	}
 
-	public function close() {
+	public function close(): bool {
 		return true;
 	}
 
@@ -44,25 +43,24 @@ class SiteSessionHandler implements SessionHandlerInterface {
 	 * @return bool
 	 * @throws Exception
 	 */
-	public function destroy($id) {
-
+	public function destroy($id): bool {
 		$session = Session::get($id);
 		if($session) $session->delete();
 		return true;
 	}
 
 	/**
-	 * @param int $lifetime
-	 * @return bool
+	 * @param int $max_lifetime
+	 * @return int
 	 * @throws Exception
 	 */
-	public function gc($lifetime) {
-		$threshold = time() - $lifetime;
+	public function gc($max_lifetime): int {
+		$threshold = time() - $max_lifetime;
 		$date_time = gmdate("Y-m-d H:i:s", $threshold);
 
 		$sql = "DELETE FROM `session` WHERE `dts_last_access` < '$date_time'";
-		$result = db::query($sql);
-		return !empty($result);
+		db::query($sql);
+		return db::affectedRows();
 	}
 
 }