Skip to content

Commit c03a217

Browse files
committed
Give Http\Client\Request a more useful constructor.
Having a more useful constructor helps keep the request simpler inside.
1 parent ae3d4a9 commit c03a217

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/Http/Client.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,7 @@ public function buildUrl($url, $query = [], $options = [])
421421
*/
422422
protected function _createRequest($method, $url, $data, $options)
423423
{
424-
$request = new Request();
425-
$request = $request->withMethod($method)
426-
->url($url)
427-
->body($data);
424+
$request = new Request($url, $method, $data);
428425

429426
if (isset($options['type'])) {
430427
$request->header($this->_typeHeaders($options['type']));

src/Http/Client/Request.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ class Request extends Message implements RequestInterface
3434
* Constructor
3535
*
3636
* Provides backwards compatible defaults for some properties.
37+
*
38+
* @param string $url The request URL
39+
* @param string $method The HTTP method to use.
40+
* @param array|string $body The request body to use.
3741
*/
38-
public function __construct()
42+
public function __construct($url = '', $method = self::METHOD_GET, $data = null)
3943
{
40-
$this->method = static::METHOD_GET;
41-
44+
$this->validateMethod($method);
45+
$this->method = $method;
46+
$this->uri = $this->createUri($url);
47+
$this->body($data);
4248
$this->header([
4349
'Connection' => 'close',
4450
'User-Agent' => 'CakePHP'

0 commit comments

Comments
 (0)