Skip to content

Commit

Permalink
Merge branch '3.1/release/3.1.3' into 3.1/master
Browse files Browse the repository at this point in the history
  • Loading branch information
zombor committed May 2, 2011
2 parents a603a4d + bc907b6 commit 05fa214
Show file tree
Hide file tree
Showing 19 changed files with 445 additions and 173 deletions.
4 changes: 2 additions & 2 deletions classes/kohana/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
class Kohana_Core {

// Release version and codename
const VERSION = '3.1.2';
const CODENAME = 'Hirondelle';
const VERSION = '3.1.3';
const CODENAME = 'araea';

// Common environment type constants for consistency and convenience
const PRODUCTION = 1;
Expand Down
2 changes: 1 addition & 1 deletion classes/kohana/http/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Kohana_HTTP_Header extends ArrayObject {
* @param array $header_commas_allowed Header values where commas are not delimiters (usually date)
* @return array
*/
public static function parse_header_values(array $header_values, array $header_commas_allowed = array('user-agent', 'date', 'expires'))
public static function parse_header_values(array $header_values, array $header_commas_allowed = array('user-agent', 'date', 'expires', 'last-modified'))
{
/**
* @see http://www.w3.org/Protocols/rfc2616/rfc2616.html
Expand Down
32 changes: 22 additions & 10 deletions classes/kohana/kohana/exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class Kohana_Kohana_Exception extends Exception {
* throw new Kohana_Exception('Something went terrible wrong, :user',
* array(':user' => $user));
*
* @param string error message
* @param array translation variables
* @param integer the exception code
* @param string error message
* @param array translation variables
* @param integer|string the exception code
* @return void
*/
public function __construct($message, array $variables = NULL, $code = 0)
Expand All @@ -48,11 +48,15 @@ public function __construct($message, array $variables = NULL, $code = 0)
Kohana_Exception::$php_errors[E_DEPRECATED] = 'Deprecated';
}

// Save the unmodified code
// @link http://bugs.php.net/39615
$this->code = $code;

// Set the message
$message = __($message, $variables);

// Pass the message to the parent
parent::__construct($message, $code);
// Pass the message and integer code to the parent
parent::__construct($message, (int) $code);
}

/**
Expand Down Expand Up @@ -115,7 +119,7 @@ public static function handler(Exception $e)
}
}
}

// Create a text version of the exception
$error = Kohana_Exception::text($e);

Expand All @@ -127,13 +131,13 @@ public static function handler(Exception $e)
// Make sure the logs are written
Kohana::$log->write();
}

if (Kohana::$is_cli)
{
// Just display the text of the exception
echo "\n{$error}\n";

return TRUE;
exit(1);
}

if ( ! headers_sent())
Expand All @@ -144,6 +148,14 @@ public static function handler(Exception $e)
header('Content-Type: text/html; charset='.Kohana::$charset, TRUE, $http_header_status);
}

if (Request::$current !== NULL AND Request::current()->is_ajax() === TRUE)
{
// Just display the text of the exception
echo "\n{$error}\n";

exit(1);
}

// Start an output buffer
ob_start();

Expand All @@ -161,8 +173,8 @@ public static function handler(Exception $e)

// Display the contents of the output buffer
echo ob_get_clean();
return TRUE;

exit(1);
}
catch (Exception $e)
{
Expand Down
2 changes: 1 addition & 1 deletion classes/kohana/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Kohana_Log {

// Log message levels
// Log message levels - Windows users see PHP Bug #18090
const EMERGENCY = LOG_EMERG; // 0
const ALERT = LOG_ALERT; // 1
const CRITICAL = LOG_CRIT; // 2
Expand Down
107 changes: 48 additions & 59 deletions classes/kohana/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public static function factory($uri = TRUE, Cache $cache = NULL, $injected_route
// Use the specified URI
$uri = $options['uri'];
}
elseif ($uri === TRUE)
{
$uri = '';
}

if (isset($options['method']))
{
Expand Down Expand Up @@ -727,11 +731,24 @@ public function __construct($uri, Cache $cache = NULL, $injected_routes = array(
// Assign injected routes
$this->_injected_routes = $injected_routes;

// Cleanse query parameters from URI (faster that parse_url())
$split_uri = explode('?', $uri);
$uri = array_shift($split_uri);

// Initial request has global $_GET already applied
if (Request::$initial !== NULL)
{
if ($split_uri)
{
parse_str($split_uri[0], $this->_get);
}
}

// Detect protocol (if present)
/**
* @todo make this smarter, search for localhost etc
*/
if (strpos($uri, '://') === FALSE)
// Always default to an internal request if we don't have an initial.
// This prevents the default index.php from being able to proxy
// external pages.
if (Request::$initial === NULL OR strpos($uri, '://') === FALSE)
{
// Remove trailing slashes from the URI
$uri = trim($uri, '/');
Expand Down Expand Up @@ -826,25 +843,31 @@ public function uri(array $params = NULL)
if ( ! isset($params['directory']))
{
// Add the current directory
$params['directory'] = $this->_directory;
$params['directory'] = $this->directory();
}

if ( ! isset($params['controller']))
{
// Add the current controller
$params['controller'] = $this->_controller;
$params['controller'] = $this->controller();
}

if ( ! isset($params['action']))
{
// Add the current action
$params['action'] = $this->_action;
$params['action'] = $this->action();
}

// Add the current parameters
$params += $this->_params;

return $this->_route->uri($params);
$uri = $this->_route->uri($params);

if ( ! $query = $this->query())
return $uri;
else
return $uri . '?' . http_build_query($query, NULL, '&');

}

/**
Expand All @@ -861,7 +884,12 @@ public function uri(array $params = NULL)
public function url(array $params = NULL, $protocol = NULL)
{
// Create a URI with the current route and convert it to a URL
return URL::site($this->uri($params), $protocol);
$url = URL::site($this->uri($params), $protocol);

if ( ! $query = $this->query())
return $url;
else
return $url . '?' . http_build_query($query, NULL, '&');
}

/**
Expand Down Expand Up @@ -893,45 +921,15 @@ public function param($key = NULL, $default = NULL)
*
* @return $this
* @uses Request::$messages
* @deprecated This should not be here, it belongs in\n
* Response::send_headers() where it is implemented correctly.
*/
public function send_headers()
{
if ( ! headers_sent())
{
if (isset($_SERVER['SERVER_PROTOCOL']))
{
// Use the default server protocol
$protocol = $_SERVER['SERVER_PROTOCOL'];
}
else
{
// Default to using newer protocol
$protocol = 'HTTP/1.1';
}

// HTTP status line
header($protocol.' '.$this->status.' '.Request::$messages[$this->status]);

foreach ($this->headers as $name => $value)
{
if (is_string($name))
{
// Combine the name and value to make a raw header
$value = "{$name}: {$value}";
}

// Send the raw header
header($value, TRUE);
}

foreach (Session::$instances as $session)
{
// Sessions will most likely write cookies, which will be sent
// with the headers
$session->write();
}
}
if ( ! ($response = $this->response()) instanceof Response)
return $this;

$response->send_headers();
return $this;
}

Expand Down Expand Up @@ -1309,7 +1307,7 @@ public function headers($key = NULL, $value = NULL)
return $this;
}

if ( ! $this->_header AND $this->is_initial())
if ($this->_header->count() === 0 AND $this->is_initial())
{
// Lazy load the request headers
$this->_header = HTTP::request_headers();
Expand Down Expand Up @@ -1407,23 +1405,14 @@ public function render($response = TRUE)
return (string) $this->_response;
}

if ( ! $this->_post)
{
$body = $this->_body;
}
else
{
$this->_header['content-type'] = 'application/x-www-form-urlencoded';
$body = HTTP::www_form_urlencode($this->_post);
}

if ( ! $this->_get)
if ( ! $post = $this->post())
{
$query_string = '';
$body = $this->body();
}
else
{
$query_string = '?'.HTTP::www_form_urlencode($this->query());
$this->headers('content-type', 'application/x-www-form-urlencoded');
$body = http_build_query($post, NULL, '&');
}

// Prepare cookies
Expand All @@ -1441,7 +1430,7 @@ public function render($response = TRUE)
$this->_header['cookie'] = implode('; ', $cookie_string);
}

$output = $this->_method.' '.$this->uri($this->param()).$query_string.' '.$this->protocol()."\n";
$output = $this->method().' '.$this->uri($this->param()).' '.strtoupper($this->protocol()).'/'.HTTP::$version."\n";
$output .= (string) $this->_header;
$output .= $body;

Expand Down
53 changes: 25 additions & 28 deletions classes/kohana/request/client/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ public function execute(Request $request)
$previous = Request::$current;
Request::$current = $request;

// Resolve the POST fields
if ($post = $request->post())
{
$request->body(http_build_query($post, NULL, '&'))
->headers('content-type', 'application/x-www-form-urlencoded');
}

try
{
// If PECL_HTTP is present, use extension to complete request
Expand Down Expand Up @@ -196,16 +203,19 @@ protected function _http_execute(Request $request)
// Create an http request object
$http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]);

// Set custom options
$http_request->setOptions($this->_options);
if ($this->_options)
{
// Set custom options
$http_request->setOptions($this->_options);
}

// Set headers
$http_request->setHeaders($request->headers()->getArrayCopy());

// Set cookies
$http_request->setCookies($request->cookie());

// Set body
// Set the body
$http_request->setBody($request->body());

try
Expand Down Expand Up @@ -251,30 +261,11 @@ protected function _curl_execute(Request $request)
// Set the request method
$options[CURLOPT_CUSTOMREQUEST] = $request->method();

switch ($request->method())
{
case Request::POST:
// Set the request post fields
$options[CURLOPT_POSTFIELDS] = http_build_query($request->post(), NULL, '&');
break;
case Request::PUT:
// Create a temporary file to hold the body
$body = tmpfile();

// Write the request body into the temp file
fwrite($body, $request->body());

// Get the length of the content
$length = ftell($body);

// Rewind to the beginning of the file
fseek($body, 0);

// Set the request body
$options[CURLOPT_INFILE] = $body;
$options[CURLOPT_INFILESIZE] = $length;
break;
}
// Set the request body. This is perfectly legal in CURL even
// if using a request other than POST. PUT does support this method
// and DOES NOT require writing data to disk before putting it, if
// reading the PHP docs you may have got that impression. SdF
$options[CURLOPT_POSTFIELDS] = $request->body();

// Process headers
if ($headers = $request->headers())
Expand Down Expand Up @@ -361,12 +352,18 @@ protected function _native_execute(Request $request)
$request->headers('cookie', http_build_query($cookies, NULL, '; '));
}

// Get the message body
$body = $request->body();

// Set the content length
$request->headers('content-length', strlen($body));

// Create the context
$options = array(
$request->protocol() => array(
'method' => $request->method(),
'header' => (string) $request->headers(),
'content' => $request->body(),
'content' => $body,
'user-agent' => 'Kohana Framework '.Kohana::VERSION.' ('.Kohana::CODENAME.')'
)
);
Expand Down

0 comments on commit 05fa214

Please sign in to comment.