Skip to content
Permalink
Browse files

Start extracting a base Message class.

  • Loading branch information...
markstory committed Dec 28, 2012
1 parent 6559721 commit 0d63455d4f162808d2a9d185369607ffcb44bd9a
Showing with 67 additions and 53 deletions.
  1. +62 −0 lib/Cake/Network/Http/Message.php
  2. +2 −21 lib/Cake/Network/Http/Request.php
  3. +3 −32 lib/Cake/Network/Http/Response.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);
}
}
@@ -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.
*
@@ -41,8 +37,6 @@ class Request {
protected $_url;
protected $_cookies = [];
/**
* Headers to be sent.
*
@@ -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.
*
@@ -13,6 +13,8 @@
*/
namespace Cake\Network\Http;
use Cake\Network\Http\Message;
/**
* Implements methods for HTTP responses.
*
@@ -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.
@@ -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
*
@@ -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
*

0 comments on commit 0d63455

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