Skip to content

Commit

Permalink
Give Http\Client\Request a more useful constructor.
Browse files Browse the repository at this point in the history
Having a more useful constructor helps keep the request simpler inside.
  • Loading branch information
markstory committed May 17, 2016
1 parent ae3d4a9 commit c03a217
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/Http/Client.php
Expand Up @@ -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']));
Expand Down
12 changes: 9 additions & 3 deletions src/Http/Client/Request.php
Expand Up @@ -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'
Expand Down

0 comments on commit c03a217

Please sign in to comment.