Skip to content

Commit 0d63455

Browse files
committed
Start extracting a base Message class.
1 parent 6559721 commit 0d63455

File tree

3 files changed

+67
-53
lines changed

3 files changed

+67
-53
lines changed

lib/Cake/Network/Http/Message.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* Redistributions of files must retain the above copyright notice.
8+
*
9+
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
10+
* @link http://cakephp.org CakePHP(tm) Project
11+
* @since CakePHP(tm) v 3.0.0
12+
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
13+
*/
14+
namespace Cake\Network\Http;
15+
16+
/**
17+
* Base class for other HTTP requests/responses
18+
*
19+
* Defines some common helper methods, constants
20+
* and properties.
21+
*/
22+
class Message {
23+
24+
const STATUS_OK = 200;
25+
const STATUS_CREATED = 201;
26+
const STATUS_ACCEPTED = 202;
27+
28+
const METHOD_GET = 'GET';
29+
const METHOD_POST = 'POST';
30+
const METHOD_PUT = 'PUT';
31+
const METHOD_DELETE = 'DELETE';
32+
const METHOD_PATCH = 'PATCH';
33+
34+
/**
35+
* The array of headers in the response.
36+
*
37+
* @var array
38+
*/
39+
protected $_headers;
40+
41+
/**
42+
* The array of cookies in the response.
43+
*
44+
* @var array
45+
*/
46+
protected $_cookies;
47+
48+
49+
/**
50+
* Normalize header names to Camel-Case form.
51+
*
52+
* @param string $name The header name to normalize.
53+
* @return string Normalized header name.
54+
*/
55+
protected function _normalizeHeader($name) {
56+
$parts = explode('-', trim($name));
57+
$parts = array_map('strtolower', $parts);
58+
$parts = array_map('ucfirst', $parts);
59+
return implode('-', $parts);
60+
}
61+
62+
}

lib/Cake/Network/Http/Request.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,16 @@
1414
namespace Cake\Network\Http;
1515

1616
use Cake\Error;
17+
use Cake\Network\Http\Message;
1718

1819
/**
1920
* Implements methods for HTTP requests.
2021
*
2122
* Used by Cake\Network\Http\Client to contain request information
2223
* for making requests.
2324
*/
24-
class Request {
25+
class Request extends Message {
2526

26-
const METHOD_GET = 'GET';
27-
const METHOD_POST = 'POST';
28-
const METHOD_PUT = 'PUT';
29-
const METHOD_DELETE = 'DELETE';
30-
const METHOD_PATCH = 'PATCH';
3127
/**
3228
* HTTP Version being used.
3329
*
@@ -41,8 +37,6 @@ class Request {
4137

4238
protected $_url;
4339

44-
protected $_cookies = [];
45-
4640
/**
4741
* Headers to be sent.
4842
*
@@ -132,19 +126,6 @@ public function headers() {
132126
return $this->_headers;
133127
}
134128

135-
/**
136-
* Normalize header names to Camel-Case form.
137-
*
138-
* @param string $name The header name to normalize.
139-
* @return string Normalized header name.
140-
*/
141-
protected function _normalizeHeader($name) {
142-
$parts = explode('-', $name);
143-
$parts = array_map('strtolower', $parts);
144-
$parts = array_map('ucfirst', $parts);
145-
return implode('-', $parts);
146-
}
147-
148129
/**
149130
* Get/set the content or body for the request.
150131
*

lib/Cake/Network/Http/Response.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
namespace Cake\Network\Http;
1515

16+
use Cake\Network\Http\Message;
17+
1618
/**
1719
* Implements methods for HTTP responses.
1820
*
@@ -57,11 +59,7 @@
5759
*
5860
* `$content = $response['code'];`
5961
*/
60-
class Response implements \ArrayAccess {
61-
62-
const STATUS_OK = 200;
63-
const STATUS_CREATED = 201;
64-
const STATUS_ACCEPTED = 202;
62+
class Response extends Message implements \ArrayAccess {
6563

6664
/**
6765
* The status code of the response.
@@ -70,20 +68,6 @@ class Response implements \ArrayAccess {
7068
*/
7169
protected $_code;
7270

73-
/**
74-
* The array of headers in the response.
75-
*
76-
* @var array
77-
*/
78-
protected $_headers;
79-
80-
/**
81-
* The array of cookies in the response.
82-
*
83-
* @var array
84-
*/
85-
protected $_cookies;
86-
8771
/**
8872
* The response body
8973
*
@@ -181,19 +165,6 @@ protected function _parseCookie($value) {
181165
$this->_cookies[$name] = $cookie;
182166
}
183167

184-
/**
185-
* Normalize header names to Camel-Case form.
186-
*
187-
* @param string $name The header name to normalize.
188-
* @return string Normalized header name.
189-
*/
190-
protected function _normalizeHeader($name) {
191-
$parts = explode('-', trim($name));
192-
$parts = array_map('strtolower', $parts);
193-
$parts = array_map('ucfirst', $parts);
194-
return implode('-', $parts);
195-
}
196-
197168
/**
198169
* Check if the response was OK
199170
*

0 commit comments

Comments
 (0)