Permalink
Browse files

Merge remote-tracking branch 'origin/3.2/develop' into 3.2/develop

  • Loading branch information...
2 parents 1dc0612 + bdeee25 commit 5c2eefe14ca0323e439523ba074c47681f166016 @zombor zombor committed Aug 23, 2012
@@ -104,7 +104,7 @@ public static function parse_accept_header($accepts = NULL)
*
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2
* @param string $charset charset string to parse
- * @return array
+ * @return array
* @since 3.2.0
*/
public static function parse_charset_header($charset = NULL)
@@ -123,7 +123,7 @@ public static function parse_charset_header($charset = NULL)
*
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
* @param string $encoding charset string to parse
- * @return array
+ * @return array
* @since 3.2.0
*/
public static function parse_encoding_header($encoding = NULL)
@@ -149,7 +149,7 @@ public static function parse_encoding_header($encoding = NULL)
*
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
* @param string $language charset string to parse
- * @return array
+ * @return array
* @since 3.2.0
*/
public static function parse_language_header($language = NULL)
@@ -346,7 +346,6 @@ public function offsetSet($index, $newval, $replace = TRUE)
{
// Ensure the index is lowercase
$index = strtolower($index);
- $newval = (string) $newval;
if ($replace OR ! $this->offsetExists($index))
{
@@ -428,7 +427,7 @@ public function exchangeArray($input)
/**
* Parses a HTTP Message header line and applies it to this HTTP_Header
- *
+ *
* $header = $response->headers();
* $header->parse_header_string(NULL, 'content-type: application/json');
*
@@ -457,13 +456,13 @@ public function parse_header_string($resource, $header_line)
* request `Accept:` header. If the `$explicit` argument is `TRUE`,
* only precise matches will be returned, excluding all wildcard (`*`)
* directives.
- *
+ *
* // Accept: application/xml; application/json; q=.5; text/html; q=.2, text/*
* // Accept quality for application/json
- *
+ *
* // $quality = 0.5
* $quality = $request->headers()->accepts_at_quality('application/json');
- *
+ *
* // $quality_explicit = FALSE
* $quality_explicit = $request->headers()->accepts_at_quality('text/plain', TRUE);
*
@@ -539,20 +538,20 @@ public function accepts_at_quality($type, $explicit = FALSE)
* Returns the preferred response content type based on the accept header
* quality settings. If items have the same quality value, the first item
* found in the array supplied as `$types` will be returned.
- *
+ *
* // Get the preferred acceptable content type
* // Accept: text/html, application/json; q=.8, text/*
* $result = $header->preferred_accept(array(
* 'text/html'
* 'text/rtf',
* 'application/json'
* )); // $result = 'application/json'
- *
+ *
* $result = $header->preferred_accept(array(
* 'text/rtf',
* 'application/xml'
* ), TRUE); // $result = FALSE (none matched explicitly)
- *
+ *
*
* @param array $types the content types to examine
* @param boolean $explicit only allow explicit references, no wildcards
@@ -582,7 +581,7 @@ public function preferred_accept(array $types, $explicit = FALSE)
* Returns the quality of the supplied `$charset` argument. This method
* will automatically parse the `Accept-Charset` header if present and
* return the associated resolved quality value.
- *
+ *
* // Accept-Charset: utf-8, utf-16; q=.8, iso-8859-1; q=.5
* $quality = $header->accepts_charset_at_quality('utf-8');
* // $quality = (float) 1
@@ -627,7 +626,7 @@ public function accepts_charset_at_quality($charset)
/**
* Returns the preferred charset from the supplied array `$charsets` based
* on the `Accept-Charset` header directive.
- *
+ *
* // Accept-Charset: utf-8, utf-16; q=.8, iso-8859-1; q=.5
* $charset = $header->preferred_charset(array(
* 'utf-10', 'ascii', 'utf-16', 'utf-8'
@@ -661,7 +660,7 @@ public function preferred_charset(array $charsets)
* is usually compression such as `gzip`, but could be some other
* message encoding algorithm. This method allows explicit checks to be
* done ignoring wildcards.
- *
+ *
* // Accept-Encoding: compress, gzip, *; q=.5
* $encoding = $header->accepts_encoding_at_quality('gzip');
* // $encoding = (float) 1.0s
@@ -714,7 +713,7 @@ public function accepts_encoding_at_quality($encoding, $explicit = FALSE)
* Returns the preferred message encoding type based on quality, and can
* optionally ignore wildcard references. If two or more encodings have the
* same quality, the first listed in `$encodings` will be returned.
- *
+ *
* // Accept-Encoding: compress, gzip, *; q.5
* $encoding = $header->preferred_encoding(array(
* 'gzip', 'bzip', 'blowfish'
@@ -749,14 +748,14 @@ public function preferred_encoding(array $encodings, $explicit = FALSE)
* Returns the quality of `$language` supplied, optionally ignoring
* wildcards if `$explicit` is set to a non-`FALSE` value. If the quality
* is not found, `0.0` is returned.
- *
+ *
* // Accept-Language: en-us, en-gb; q=.7, en; q=.5
* $lang = $header->accepts_language_at_quality('en-gb');
* // $lang = (float) 0.7
- *
+ *
* $lang2 = $header->accepts_language_at_quality('en-au');
* // $lang2 = (float) 0.5
- *
+ *
* $lang3 = $header->accepts_language_at_quality('en-au', TRUE);
* // $lang3 = (float) 0.0
*
@@ -814,7 +813,7 @@ public function accepts_language_at_quality($language, $explicit = FALSE)
/**
* Returns the preferred language from the supplied array `$languages` based
* on the `Accept-Language` header directive.
- *
+ *
* // Accept-Language: en-us, en-gb; q=.7, en; q=.5
* $lang = $header->preferred_language(array(
* 'en-gb', 'en-au', 'fr', 'es'
@@ -848,7 +847,7 @@ public function preferred_language(array $languages, $explicit = FALSE)
* Sends headers to the php processor, or supplied `$callback` argument.
* This method formats the headers correctly for output, re-instating their
* capitalization for transmission.
- *
+ *
* [!!] if you supply a custom header handler via `$callback`, it is
* recommended that `$response` is returned
*
@@ -949,4 +948,4 @@ protected function _send_headers_to_php(array $headers, $replace)
return $this;
}
-} // End Kohana_HTTP_Header
+} // End Kohana_HTTP_Header
@@ -24,8 +24,10 @@ public function _send_message(Request $request)
// Response headers
$response_headers = array();
+ $options = array();
+
// Set the request method
- $options[CURLOPT_CUSTOMREQUEST] = $request->method();
+ $options = $this->_set_curl_request_method($request, $options);
// Set the request body. This is perfectly legal in CURL even
// if using a request other than POST. PUT does support this method
@@ -107,4 +109,27 @@ public function _send_message(Request $request)
return $response;
}
+ /**
+ * Sets the appropriate curl request options. Uses the responding options
+ * for POST and PUT, uses CURLOPT_CUSTOMREQUEST otherwise
+ * @param Request $request
+ * @param array $options
+ * @return array
+ */
+ public function _set_curl_request_method(Request $request, array $options)
+ {
+ switch ($request->method()) {
+ case Request::POST:
+ $options[CURLOPT_POST] = TRUE;
+ break;
+ case Request::PUT:
+ $options[CURLOPT_PUT] = TRUE;
+ break;
+ default:
+ $options[CURLOPT_CUSTOMREQUEST] = $request->method();
+ break;
+ }
+ return $options;
+ }
+
} // End Kohana_Request_Client_Curl
View
@@ -67,7 +67,7 @@ class Kohana_Route {
public static $cache = FALSE;
/**
- * @var array
+ * @var array
*/
protected static $_routes = array();
@@ -155,16 +155,18 @@ public static function cache($save = FALSE)
{
if ($save === TRUE)
{
- $routes = array();
- foreach (Route::$_routes as $name => $route)
+ try
{
- if ( ! $route->is_closure())
- {
- $routes[$name] = $route;
- }
+ // Cache all defined routes
+ Kohana::cache('Route::cache()', Route::$_routes);
+ }
+ catch (Exception $e)
+ {
+ // We most likely have a lambda in a route, which cannot be cached
+ throw new Kohana_Exception('One or more routes could not be cached (:message)', array(
+ ':message' => $e->getMessage(),
+ ));
}
- // Cache all defined routes
- Kohana::cache('Route::cache()', $routes);
}
else
{
@@ -348,7 +350,7 @@ public function __construct($uri = NULL, $regex = NULL)
* 'controller' => 'welcome',
* 'action' => 'index'
* ));
- *
+ *
* If no parameter is passed, this method will act as a getter.
*
* @param array $defaults key values
@@ -553,9 +555,4 @@ public function uri(array $params = NULL)
return $uri;
}
- protected function is_closure()
- {
- return is_object($this->_callback) AND get_class($this->_callback) == 'Closure';
- }
-
} // End Route
@@ -29,33 +29,3 @@ There are a few things you'll want to do with your application before moving int
'profile' => Kohana::$environment !== Kohana::PRODUCTION,
'caching' => Kohana::$environment === Kohana::PRODUCTION,
));
-
-`index.php`:
-
- /**
- * Execute the main request using PATH_INFO. If no URI source is specified,
- * the URI will be automatically detected.
- */
- $request = Request::instance($_SERVER['PATH_INFO']);
-
- // Attempt to execute the response
- $request->execute();
-
- if ($request->send_headers()->response)
- {
- // Get the total memory and execution time
- $total = array(
- '{memory_usage}' => number_format((memory_get_peak_usage() - KOHANA_START_MEMORY) / 1024, 2).'KB',
- '{execution_time}' => number_format(microtime(TRUE) - KOHANA_START_TIME, 5).' seconds');
-
- // Insert the totals into the response
- $request->response = str_replace(array_keys($total), $total, $request->response);
- }
-
-
- /**
- * Display the request response.
- */
- echo $request->response;
-
-
@@ -114,15 +114,6 @@ public function test_cache_stores_route_objects()
$this->assertEquals($routes, Route::all());
}
- public function test_cache_does_not_cache_lambdas()
- {
- Route::set('lambda', function($uri) {} );
-
- Route::cache(TRUE);
- $this->assertTrue(Route::cache());
- $this->assertArrayNotHasKey('lambda', Route::all());
- }
-
/**
* Route::cache() should return FALSE if cached routes could not be found
*

0 comments on commit 5c2eefe

Please sign in to comment.