Procházet zdrojové kódy

check isSafe when __destruct

walkor před 2 roky
rodič
revize
1fa2c3308d
2 změnil soubory, kde provedl 39 přidání a 1 odebrání
  1. 19 1
      src/Protocols/Http/Request.php
  2. 20 0
      src/Protocols/Http/Session.php

+ 19 - 1
src/Protocols/Http/Request.php

@@ -93,6 +93,13 @@ class Request implements Stringable
     protected array $data = [];
 
     /**
+     * Is safe.
+     *
+     * @var bool
+     */
+    protected $isSafe = true;
+
+    /**
      * Enable cache.
      *
      * @var bool
@@ -731,6 +738,17 @@ class Request implements Stringable
         unset($this->properties[$name]);
     }
 
+
+    /**
+     * __wakeup.
+     *
+     * @return void
+     */
+    public function __wakeup()
+    {
+        $this->isSafe = false;
+    }
+
     /**
      * __destruct.
      *
@@ -738,7 +756,7 @@ class Request implements Stringable
      */
     public function __destruct()
     {
-        if (isset($this->data['files'])) {
+        if (isset($this->data['files']) && $this->isSafe) {
             clearstatcache();
             array_walk_recursive($this->data['files'], function ($value, $key) {
                 if ($key === 'tmp_name' && is_file($value)) {

+ 20 - 0
src/Protocols/Http/Session.php

@@ -149,6 +149,13 @@ class Session
     protected string $sessionId;
 
     /**
+     * Is safe.
+     *
+     * @var bool
+     */
+    protected $isSafe = true;
+
+    /**
      * Session constructor.
      *
      * @param string $sessionId
@@ -417,6 +424,16 @@ class Session
     }
 
     /**
+     * __wakeup.
+     *
+     * @return void
+     */
+    public function __wakeup()
+    {
+        $this->isSafe = false;
+    }
+
+    /**
      * __destruct.
      *
      * @return void
@@ -424,6 +441,9 @@ class Session
      */
     public function __destruct()
     {
+        if (!$this->isSafe) {
+            return;
+        }
         $this->save();
         if (random_int(1, static::$gcProbability[1]) <= static::$gcProbability[0]) {
             $this->gc();