Browse Source

Give Http\Client\Request a more useful constructor.

Having a more useful constructor helps keep the request simpler inside.
Mark Story 9 years ago
parent
commit
c03a217ab3
2 changed files with 10 additions and 7 deletions
  1. 1 4
      src/Http/Client.php
  2. 9 3
      src/Http/Client/Request.php

+ 1 - 4
src/Http/Client.php

@@ -421,10 +421,7 @@ class Client
      */
     protected function _createRequest($method, $url, $data, $options)
     {
-        $request = new Request();
-        $request = $request->withMethod($method)
-            ->url($url)
-            ->body($data);
+        $request = new Request($url, $method, $data);
 
         if (isset($options['type'])) {
             $request->header($this->_typeHeaders($options['type']));

+ 9 - 3
src/Http/Client/Request.php

@@ -34,11 +34,17 @@ class Request extends Message implements RequestInterface
      * Constructor
      *
      * Provides backwards compatible defaults for some properties.
+     *
+     * @param string $url The request URL
+     * @param string $method The HTTP method to use.
+     * @param array|string $body The request body to use.
      */
-    public function __construct()
+    public function __construct($url = '', $method = self::METHOD_GET, $data = null)
     {
-        $this->method = static::METHOD_GET;
-
+        $this->validateMethod($method);
+        $this->method = $method;
+        $this->uri = $this->createUri($url);
+        $this->body($data);
         $this->header([
             'Connection' => 'close',
             'User-Agent' => 'CakePHP'