소스 검색

setGet setPost setHeaders

walkor 1 년 전
부모
커밋
7ba75977a2
1개의 변경된 파일56개의 추가작업 그리고 0개의 파일을 삭제
  1. 56 0
      src/Protocols/Http/Request.php

+ 56 - 0
src/Protocols/Http/Request.php

@@ -93,6 +93,13 @@ class Request implements Stringable
     protected bool $isSafe = true;
 
     /**
+     * Is dirty.
+     *
+     * @var bool
+     */
+    protected bool $isDirty = false;
+
+    /**
      * Enable cache.
      *
      * @var bool
@@ -131,6 +138,19 @@ class Request implements Stringable
     }
 
     /**
+     * Set get.
+     *
+     * @param array $get
+     * @return Request
+     */
+    public function setGet(array $get): Request
+    {
+        $this->isDirty = true;
+        $this->data['get'] = $get;
+        return $this;
+    }
+
+    /**
      * Get post.
      *
      * @param string|null $name
@@ -149,6 +169,19 @@ class Request implements Stringable
     }
 
     /**
+     * Set post.
+     *
+     * @param array $post
+     * @return Request
+     */
+    public function setPost(array $post): Request
+    {
+        $this->isDirty = true;
+        $this->data['post'] = $post;
+        return $this;
+    }
+
+    /**
      * Get header item by name.
      *
      * @param string|null $name
@@ -168,6 +201,18 @@ class Request implements Stringable
     }
 
     /**
+     * Set headers.
+     * @param array $headers
+     * @return $this
+     */
+    public function setHeaders(array $headers): Request
+    {
+        $this->isDirty = true;
+        $this->data['headers'] = $headers;
+        return $this;
+    }
+
+    /**
      * Get cookie item by name.
      *
      * @param string|null $name
@@ -747,4 +792,15 @@ class Request implements Stringable
             });
         }
     }
+
+    /**
+     * @return void
+     */
+    public function __clone()
+    {
+        if ($this->isDirty) {
+            unset($this->data['get'], $this->data['post'], $this->data['headers']);
+        }
+    }
+
 }