Skip to content
Permalink
Browse files

Give Http\Client\Request a more useful constructor.

Having a more useful constructor helps keep the request simpler inside.
  • Loading branch information...
markstory committed May 17, 2016
1 parent ae3d4a9 commit c03a217ab39b274c8b0b75d13f27935baf107b2b
Showing with 10 additions and 7 deletions.
  1. +1 −4 src/Http/Client.php
  2. +9 −3 src/Http/Client/Request.php
@@ -421,10 +421,7 @@ public function buildUrl($url, $query = [], $options = [])
*/
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']));
@@ -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'

0 comments on commit c03a217

Please sign in to comment.
You can’t perform that action at this time.