From 34a110678cf835bdd59acca30443341a3767e413 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 28 Dec 2012 00:26:41 -0500 Subject: [PATCH] Rename content() -> body() This makes methods & terms consistent between requests/responses. --- lib/Cake/Network/Http/Client.php | 4 +- lib/Cake/Network/Http/Message.php | 38 +++++++++++++++++++ lib/Cake/Network/Http/Request.php | 36 +----------------- lib/Cake/Network/Http/Response.php | 1 + .../Test/TestCase/Network/Http/ClientTest.php | 4 +- .../TestCase/Network/Http/RequestTest.php | 8 ++-- 6 files changed, 48 insertions(+), 43 deletions(-) diff --git a/lib/Cake/Network/Http/Client.php b/lib/Cake/Network/Http/Client.php index 6cf41f50e9e..f000ebd825d 100644 --- a/lib/Cake/Network/Http/Client.php +++ b/lib/Cake/Network/Http/Client.php @@ -278,7 +278,7 @@ public function buildUrl($url, $query = [], $options = []) { * * @param string $method HTTP method name. * @param string $url The url including query string. - * @param mixed $data The request body content. + * @param mixed $data The request body. * @param array $options The options to use. Contains auth, proxy etc. * @return Cake\Network\Http\Request */ @@ -286,7 +286,7 @@ protected function _createRequest($method, $url, $data, $options) { $request = new Request(); $request->method($method) ->url($url) - ->content($data); + ->body($data); if (isset($options['type'])) { $request->header($this->_typeHeaders($options['type'])); } diff --git a/lib/Cake/Network/Http/Message.php b/lib/Cake/Network/Http/Message.php index cde267f216c..f1ac8bec7d3 100644 --- a/lib/Cake/Network/Http/Message.php +++ b/lib/Cake/Network/Http/Message.php @@ -45,6 +45,12 @@ class Message { */ protected $_cookies; +/** + * HTTP Version being used. + * + * @var string + */ + protected $_version = '1.1'; /** * Normalize header names to Camel-Case form. @@ -59,4 +65,36 @@ protected function _normalizeHeader($name) { return implode('-', $parts); } +/** + * Get all cookies + * + * @return array + */ + public function cookies() { + return $this->_cookies; + } + +/** + * Get the HTTP version used. + * + * @return string + */ + public function version() { + return $this->_version; + } + +/** + * Get/set the body for the message. + * + * @param string|null $body The body for the request. Leave null for get + * @return mixed Either $this or the body value. + */ + public function body($body = null) { + if ($body === null) { + return $this->_body; + } + $this->_body = $body; + return $this; + } + } diff --git a/lib/Cake/Network/Http/Request.php b/lib/Cake/Network/Http/Request.php index 52a81624465..da82b49e23b 100644 --- a/lib/Cake/Network/Http/Request.php +++ b/lib/Cake/Network/Http/Request.php @@ -24,16 +24,9 @@ */ class Request extends Message { -/** - * HTTP Version being used. - * - * @var string - */ - protected $_version = '1.1'; - protected $_method; - protected $_content; + protected $_body; protected $_url; @@ -126,20 +119,6 @@ public function headers() { return $this->_headers; } -/** - * Get/set the content or body for the request. - * - * @param string|null $content The content for the request. Leave null for get - * @return mixed Either $this or the content value. - */ - public function content($content = null) { - if ($content === null) { - return $this->_content; - } - $this->_content = $content; - return $this; - } - /** * Get/Set cookie values. * @@ -172,17 +151,4 @@ public function cookie($name, $value = null) { return $this; } -/** - * Get all cookies - * - * @return array - */ - public function cookies() { - return $this->_cookies; - } - - public function version() { - return $this->_version; - } - } diff --git a/lib/Cake/Network/Http/Response.php b/lib/Cake/Network/Http/Response.php index 9997cdf8bf4..b7b66a6fdc4 100644 --- a/lib/Cake/Network/Http/Response.php +++ b/lib/Cake/Network/Http/Response.php @@ -86,6 +86,7 @@ class Response extends Message implements \ArrayAccess { 'body' => '_body', 'code' => '_code' ]; + /** * Constructor * diff --git a/lib/Cake/Test/TestCase/Network/Http/ClientTest.php b/lib/Cake/Test/TestCase/Network/Http/ClientTest.php index 900846fe497..634264938fd 100644 --- a/lib/Cake/Test/TestCase/Network/Http/ClientTest.php +++ b/lib/Cake/Test/TestCase/Network/Http/ClientTest.php @@ -222,7 +222,7 @@ public function testGetWithContent() { $this->isInstanceOf('Cake\Network\Http\Request'), $this->attributeEqualTo('_method', Request::METHOD_GET), $this->attributeEqualTo('_url', 'http://cakephp.org/search'), - $this->attributeEqualTo('_content', 'some data') + $this->attributeEqualTo('_body', 'some data') )) ->will($this->returnValue($response)); @@ -312,7 +312,7 @@ public function testPostWithTypeKey($type, $mime) { ->method('send') ->with($this->logicalAnd( $this->attributeEqualTo('_method', Request::METHOD_POST), - $this->attributeEqualTo('_content', $data), + $this->attributeEqualTo('_body', $data), $this->attributeEqualTo('_headers', $headers) )) ->will($this->returnValue($response)); diff --git a/lib/Cake/Test/TestCase/Network/Http/RequestTest.php b/lib/Cake/Test/TestCase/Network/Http/RequestTest.php index e34ebf43540..80736434189 100644 --- a/lib/Cake/Test/TestCase/Network/Http/RequestTest.php +++ b/lib/Cake/Test/TestCase/Network/Http/RequestTest.php @@ -57,16 +57,16 @@ public function testMethodInvalid() { } /** - * test content method. + * test body method. * * @return void */ - public function testContent() { + public function testBody() { $data = '{"json":"data"}'; $request = new Request(); - $this->assertSame($request, $request->content($data)); + $this->assertSame($request, $request->body($data)); - $this->assertEquals($data, $request->content()); + $this->assertEquals($data, $request->body()); } /**