Formatting

This commit is contained in:
Juan Basso 2010-12-04 00:58:49 -02:00
parent 874a1172a1
commit 3f910dc6c1

View file

@ -37,7 +37,6 @@ class HttpSocket extends CakeSocket {
* will be disabled and additional measures to deal with non-standard responses will be enabled. * will be disabled and additional measures to deal with non-standard responses will be enabled.
* *
* @var boolean * @var boolean
* @access public
*/ */
public $quirksMode = false; public $quirksMode = false;
@ -45,7 +44,6 @@ class HttpSocket extends CakeSocket {
* The default values to use for a request * The default values to use for a request
* *
* @var array * @var array
* @access public
*/ */
public $request = array( public $request = array(
'method' => 'GET', 'method' => 'GET',
@ -71,11 +69,10 @@ class HttpSocket extends CakeSocket {
); );
/** /**
* The default structure for storing the response * The default structure for storing the response
* *
* @var array * @var array
* @access public */
*/
public $response = array( public $response = array(
'raw' => array( 'raw' => array(
'status-line' => null, 'status-line' => null,
@ -97,7 +94,6 @@ class HttpSocket extends CakeSocket {
* Default configuration settings for the HttpSocket * Default configuration settings for the HttpSocket
* *
* @var array * @var array
* @access public
*/ */
public $config = array( public $config = array(
'persistent' => false, 'persistent' => false,
@ -119,7 +115,6 @@ class HttpSocket extends CakeSocket {
* String that represents a line break. * String that represents a line break.
* *
* @var string * @var string
* @access public
*/ */
public $lineBreak = "\r\n"; public $lineBreak = "\r\n";
@ -127,7 +122,6 @@ class HttpSocket extends CakeSocket {
* Authentication settings * Authentication settings
* *
* @var array * @var array
* @access protected
*/ */
protected $_auth = array(); protected $_auth = array();
@ -135,7 +129,6 @@ class HttpSocket extends CakeSocket {
* Proxy settings * Proxy settings
* *
* @var array * @var array
* @access protected
*/ */
protected $_proxy = array(); protected $_proxy = array();
@ -457,10 +450,10 @@ class HttpSocket extends CakeSocket {
} }
if (is_string($url)) { if (is_string($url)) {
if ($url{0} == '/') { if ($url{0} == '/') {
$url = $this->config['request']['uri']['host'].':'.$this->config['request']['uri']['port'] . $url; $url = $this->config['request']['uri']['host'] . ':' . $this->config['request']['uri']['port'] . $url;
} }
if (!preg_match('/^.+:\/\/|\*|^\//', $url)) { if (!preg_match('/^.+:\/\/|\*|^\//', $url)) {
$url = $this->config['request']['uri']['scheme'].'://'.$url; $url = $this->config['request']['uri']['scheme'] . '://' . $url;
} }
} elseif (!is_array($url) && !empty($url)) { } elseif (!is_array($url) && !empty($url)) {
return false; return false;
@ -504,6 +497,7 @@ class HttpSocket extends CakeSocket {
* Set the proxy configuration and authentication * Set the proxy configuration and authentication
* *
* @return void * @return void
* @throws Exception
*/ */
protected function _setProxyConfig() { protected function _setProxyConfig() {
if (empty($this->_proxy) || !isset($this->_proxy['host'], $this->_proxy['port'])) { if (empty($this->_proxy) || !isset($this->_proxy['host'], $this->_proxy['port'])) {
@ -570,7 +564,7 @@ class HttpSocket extends CakeSocket {
$response['body'] = $decoded['body']; $response['body'] = $decoded['body'];
if (!empty($decoded['header'])) { if (!empty($decoded['header'])) {
$response['header'] = $this->_parseHeader($this->_buildHeader($response['header']).$this->_buildHeader($decoded['header'])); $response['header'] = $this->_parseHeader($this->_buildHeader($response['header']) . $this->_buildHeader($decoded['header']));
} }
if (!empty($response['header'])) { if (!empty($response['header'])) {
@ -601,7 +595,7 @@ class HttpSocket extends CakeSocket {
if (empty($encoding)) { if (empty($encoding)) {
return array('body' => $body, 'header' => false); return array('body' => $body, 'header' => false);
} }
$decodeMethod = '_decode'.Inflector::camelize(str_replace('-', '_', $encoding)).'Body'; $decodeMethod = '_decode'.Inflector::camelize(str_replace('-', '_', $encoding)) . 'Body';
if (!is_callable(array(&$this, $decodeMethod))) { if (!is_callable(array(&$this, $decodeMethod))) {
if (!$this->quirksMode) { if (!$this->quirksMode) {
@ -663,7 +657,7 @@ class HttpSocket extends CakeSocket {
} }
$decodedBody .= $chunk; $decodedBody .= $chunk;
if ($chunkLength !== 0) { if ($chunkLength !== 0) {
$body = substr($body, $chunkLength+strlen("\r\n")); $body = substr($body, $chunkLength + strlen("\r\n"));
} }
} }
@ -741,7 +735,7 @@ class HttpSocket extends CakeSocket {
$uriTemplate = str_replace(':%port', null, $uriTemplate); $uriTemplate = str_replace(':%port', null, $uriTemplate);
} }
foreach ($uri as $property => $value) { foreach ($uri as $property => $value) {
$uriTemplate = str_replace('%'.$property, $value, $uriTemplate); $uriTemplate = str_replace('%' . $property, $value, $uriTemplate);
} }
if ($uriTemplate === '/*') { if ($uriTemplate === '/*') {
@ -907,7 +901,7 @@ class HttpSocket extends CakeSocket {
if (!$this->quirksMode && $request['uri'] === '*' && !in_array($request['method'], $asteriskMethods)) { if (!$this->quirksMode && $request['uri'] === '*' && !in_array($request['method'], $asteriskMethods)) {
throw new Exception(sprintf(__('HttpSocket::_buildRequestLine - The "*" asterisk character is only allowed for the following methods: %s. Activate quirks mode to work outside of HTTP/1.1 specs.'), join(',', $asteriskMethods))); throw new Exception(sprintf(__('HttpSocket::_buildRequestLine - The "*" asterisk character is only allowed for the following methods: %s. Activate quirks mode to work outside of HTTP/1.1 specs.'), join(',', $asteriskMethods)));
} }
return $request['method'].' '.$request['uri'].' '.$versionToken.$this->lineBreak; return $request['method'] . ' ' . $request['uri'] . ' ' . $versionToken . $this->lineBreak;
} }
/** /**
@ -960,7 +954,7 @@ class HttpSocket extends CakeSocket {
$contents = preg_replace("/\r\n(?![\t ])/", "\r\n ", $content); $contents = preg_replace("/\r\n(?![\t ])/", "\r\n ", $content);
$field = $this->_escapeToken($field); $field = $this->_escapeToken($field);
$returnHeader .= $field.': '.$contents.$this->lineBreak; $returnHeader .= $field . ': ' . $contents . $this->lineBreak;
} }
} }
return $returnHeader; return $returnHeader;
@ -1004,10 +998,9 @@ class HttpSocket extends CakeSocket {
* *
* @param array $header Header array containing one ore more 'Set-Cookie' headers. * @param array $header Header array containing one ore more 'Set-Cookie' headers.
* @return mixed Either false on no cookies, or an array of cookies recieved. * @return mixed Either false on no cookies, or an array of cookies recieved.
* @access public
* @todo Make this 100% RFC 2965 confirm * @todo Make this 100% RFC 2965 confirm
*/ */
function parseCookies($header) { public function parseCookies($header) {
if (!isset($header['Set-Cookie'])) { if (!isset($header['Set-Cookie'])) {
return false; return false;
} }
@ -1046,28 +1039,26 @@ class HttpSocket extends CakeSocket {
* *
* @param array $cookies Array of cookies to send with the request. * @param array $cookies Array of cookies to send with the request.
* @return string Cookie header string to be sent with the request. * @return string Cookie header string to be sent with the request.
* @access public
* @todo Refactor token escape mechanism to be configurable * @todo Refactor token escape mechanism to be configurable
*/ */
function buildCookies($cookies) { public function buildCookies($cookies) {
$header = array(); $header = array();
foreach ($cookies as $name => $cookie) { foreach ($cookies as $name => $cookie) {
$header[] = $name.'='.$this->_escapeToken($cookie['value'], array(';')); $header[] = $name . '=' . $this->_escapeToken($cookie['value'], array(';'));
} }
$header = $this->_buildHeader(array('Cookie' => implode('; ', $header)), 'pragmatic'); return $this->_buildHeader(array('Cookie' => implode('; ', $header)), 'pragmatic');
return $header;
} }
/** /**
* Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs) * Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs)
* *
* @param string $token Token to unescape * @param string $token Token to unescape
* @param array $chars
* @return string Unescaped token * @return string Unescaped token
* @access protected
* @todo Test $chars parameter * @todo Test $chars parameter
*/ */
function _unescapeToken($token, $chars = null) { protected function _unescapeToken($token, $chars = null) {
$regex = '/"(['.join('', $this->_tokenEscapeChars(true, $chars)).'])"/'; $regex = '/"([' . implode('', $this->_tokenEscapeChars(true, $chars)) . '])"/';
$token = preg_replace($regex, '\\1', $token); $token = preg_replace($regex, '\\1', $token);
return $token; return $token;
} }
@ -1076,12 +1067,12 @@ class HttpSocket extends CakeSocket {
* Escapes a given $token according to RFC 2616 (HTTP 1.1 specs) * Escapes a given $token according to RFC 2616 (HTTP 1.1 specs)
* *
* @param string $token Token to escape * @param string $token Token to escape
* @param array $chars
* @return string Escaped token * @return string Escaped token
* @access protected
* @todo Test $chars parameter * @todo Test $chars parameter
*/ */
function _escapeToken($token, $chars = null) { protected function _escapeToken($token, $chars = null) {
$regex = '/(['.join('', $this->_tokenEscapeChars(true, $chars)).'])/'; $regex = '/([' . implode('', $this->_tokenEscapeChars(true, $chars)) . '])/';
$token = preg_replace($regex, '"\\1"', $token); $token = preg_replace($regex, '"\\1"', $token);
return $token; return $token;
} }
@ -1090,11 +1081,11 @@ class HttpSocket extends CakeSocket {
* Gets escape chars according to RFC 2616 (HTTP 1.1 specs). * Gets escape chars according to RFC 2616 (HTTP 1.1 specs).
* *
* @param boolean $hex true to get them as HEX values, false otherwise * @param boolean $hex true to get them as HEX values, false otherwise
* @param array $chars
* @return array Escape chars * @return array Escape chars
* @access protected
* @todo Test $chars parameter * @todo Test $chars parameter
*/ */
function _tokenEscapeChars($hex = true, $chars = null) { protected function _tokenEscapeChars($hex = true, $chars = null) {
if (!empty($chars)) { if (!empty($chars)) {
$escape = $chars; $escape = $chars;
} else { } else {
@ -1110,7 +1101,7 @@ class HttpSocket extends CakeSocket {
} }
$regexChars = ''; $regexChars = '';
foreach ($escape as $key => $char) { foreach ($escape as $key => $char) {
$escape[$key] = '\\x'.str_pad(dechex(ord($char)), 2, '0', STR_PAD_LEFT); $escape[$key] = '\\x' . str_pad(dechex(ord($char)), 2, '0', STR_PAD_LEFT);
} }
return $escape; return $escape;
} }