Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start extracting a base Message class.
  • Loading branch information
markstory committed Dec 28, 2012
1 parent 6559721 commit 0d63455
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 53 deletions.
62 changes: 62 additions & 0 deletions lib/Cake/Network/Http/Message.php
@@ -0,0 +1,62 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Network\Http;

/**
* Base class for other HTTP requests/responses
*
* Defines some common helper methods, constants
* and properties.
*/
class Message {

const STATUS_OK = 200;
const STATUS_CREATED = 201;
const STATUS_ACCEPTED = 202;

const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_DELETE = 'DELETE';
const METHOD_PATCH = 'PATCH';

/**
* The array of headers in the response.
*
* @var array
*/
protected $_headers;

/**
* The array of cookies in the response.
*
* @var array
*/
protected $_cookies;


/**
* Normalize header names to Camel-Case form.
*
* @param string $name The header name to normalize.
* @return string Normalized header name.
*/
protected function _normalizeHeader($name) {
$parts = explode('-', trim($name));
$parts = array_map('strtolower', $parts);
$parts = array_map('ucfirst', $parts);
return implode('-', $parts);
}

}
23 changes: 2 additions & 21 deletions lib/Cake/Network/Http/Request.php
Expand Up @@ -14,20 +14,16 @@
namespace Cake\Network\Http;

use Cake\Error;
use Cake\Network\Http\Message;

/**
* Implements methods for HTTP requests.
*
* Used by Cake\Network\Http\Client to contain request information
* for making requests.
*/
class Request {
class Request extends Message {

const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_DELETE = 'DELETE';
const METHOD_PATCH = 'PATCH';
/**
* HTTP Version being used.
*
Expand All @@ -41,8 +37,6 @@ class Request {

protected $_url;

protected $_cookies = [];

/**
* Headers to be sent.
*
Expand Down Expand Up @@ -132,19 +126,6 @@ public function headers() {
return $this->_headers;
}

/**
* Normalize header names to Camel-Case form.
*
* @param string $name The header name to normalize.
* @return string Normalized header name.
*/
protected function _normalizeHeader($name) {
$parts = explode('-', $name);
$parts = array_map('strtolower', $parts);
$parts = array_map('ucfirst', $parts);
return implode('-', $parts);
}

/**
* Get/set the content or body for the request.
*
Expand Down
35 changes: 3 additions & 32 deletions lib/Cake/Network/Http/Response.php
Expand Up @@ -13,6 +13,8 @@
*/
namespace Cake\Network\Http;

use Cake\Network\Http\Message;

/**
* Implements methods for HTTP responses.
*
Expand Down Expand Up @@ -57,11 +59,7 @@
*
* `$content = $response['code'];`
*/
class Response implements \ArrayAccess {

const STATUS_OK = 200;
const STATUS_CREATED = 201;
const STATUS_ACCEPTED = 202;
class Response extends Message implements \ArrayAccess {

/**
* The status code of the response.
Expand All @@ -70,20 +68,6 @@ class Response implements \ArrayAccess {
*/
protected $_code;

/**
* The array of headers in the response.
*
* @var array
*/
protected $_headers;

/**
* The array of cookies in the response.
*
* @var array
*/
protected $_cookies;

/**
* The response body
*
Expand Down Expand Up @@ -181,19 +165,6 @@ protected function _parseCookie($value) {
$this->_cookies[$name] = $cookie;
}

/**
* Normalize header names to Camel-Case form.
*
* @param string $name The header name to normalize.
* @return string Normalized header name.
*/
protected function _normalizeHeader($name) {
$parts = explode('-', trim($name));
$parts = array_map('strtolower', $parts);
$parts = array_map('ucfirst', $parts);
return implode('-', $parts);
}

/**
* Check if the response was OK
*
Expand Down

0 comments on commit 0d63455

Please sign in to comment.