Kohana 2 ob_end_clean() hotfix (PHP 5.4+)
diff --git a/system/core/Kohana.php b/system/core/Kohana.php | |
index 271f917..287c271 100644 | |
--- a/system/core/Kohana.php | |
+++ b/system/core/Kohana.php | |
@@ -722,7 +722,7 @@ final class Kohana { | |
if (ob_get_level() >= self::$buffer_level) | |
{ | |
// Set the close function | |
- $close = ($flush === TRUE) ? 'ob_end_flush' : 'ob_end_clean'; | |
+ $close = ($flush === TRUE) ? 'ob_end_flush' : 'Kohana::_ob_end_clean'; | |
while (ob_get_level() > self::$buffer_level) | |
{ | |
@@ -731,7 +731,7 @@ final class Kohana { | |
} | |
// Store the Kohana output buffer | |
- ob_end_clean(); | |
+ Kohana::_ob_end_clean(); | |
} | |
} | |
@@ -2173,6 +2173,31 @@ final class Kohana { | |
return $written; | |
} | |
+ | |
+ /** | |
+ * Ends the current output buffer with callback in mind | |
+ * PHP doesn't pass the output to the callback defined in ob_start() since 5.4 | |
+ * | |
+ * @param callback $callback | |
+ * @return boolean | |
+ */ | |
+ protected static function _ob_end_clean($callback = NULL) | |
+ { | |
+ // Pre-5.4 ob_end_clean() will pass the buffer to the callback anyways | |
+ if (version_compare(PHP_VERSION, '5.4', '<')) | |
+ return ob_end_clean(); | |
+ | |
+ $output = ob_get_contents(); | |
+ | |
+ if ($callback === NULL) | |
+ { | |
+ $handlers = ob_list_handlers(); | |
+ $callback = isset($handlers[ob_get_level() - 1]) ? $handlers[ob_get_level() - 1] : NULL; | |
+ } | |
+ | |
+ return is_callable($callback) | |
+ ? ob_end_clean() AND call_user_func($callback, $output) | |
+ : ob_end_clean(); | |
+ } | |
} // End Kohana | |
@@ -2309,4 +2334,4 @@ class Kohana_404_Exception extends Kohana_Exception { | |
header('HTTP/1.1 404 File Not Found'); | |
} | |
-} // End Kohana 404 Exception | |
\ No newline at end of file | |
+} // End Kohana 404 Exception |
This comment has been minimized.
This comment has been minimized.
Mothod get of helper Arr public static function get($array, $key, $default = NULL) see more: http://kohanaframework.org/3.2/guide/api/Kohana_Arr#get |
This comment has been minimized.
This comment has been minimized.
Thank you for this dist. Did wonders to our crappy legacy code! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Hi!
Kohana 2 doesn't have get method in Arr helper. Line 45 ($callback = arr::get(ob_list_handlers(), ob_get_level() - 1);) cause error "Call to undefined method arr::get() in...".
Changing it to:
$_arr = ob_list_handlers();
$callback = $_arr[ob_get_level() - 1];
Works for me.
Anyway thnx for such a useful patch!