diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-05-18 00:14:07 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-18 00:14:07 +0000 |
commit | fd0c0a608a5de2b26c29d3c44a7929e5a3b2c042 (patch) | |
tree | 387f2628cae3580b7f09682de6e908d002c5fbb0 /kohana/core | |
parent | 5a6aef9c23930b1de609c9914297e0f97bc49a11 (diff) |
Updated kohana and modules/unit_test to upstream r4356
Diffstat (limited to 'kohana/core')
-rw-r--r-- | kohana/core/Benchmark.php | 2 | ||||
-rw-r--r-- | kohana/core/Kohana.php | 239 |
2 files changed, 128 insertions, 113 deletions
diff --git a/kohana/core/Benchmark.php b/kohana/core/Benchmark.php index 09909126..3bb6d04f 100644 --- a/kohana/core/Benchmark.php +++ b/kohana/core/Benchmark.php @@ -109,7 +109,7 @@ final class Benchmark { * * @return integer */ - private function memory_usage() + private static function memory_usage() { static $func; diff --git a/kohana/core/Kohana.php b/kohana/core/Kohana.php index 0ee6f631..ed87902e 100644 --- a/kohana/core/Kohana.php +++ b/kohana/core/Kohana.php @@ -209,12 +209,6 @@ final class Kohana { { Benchmark::start(SYSTEM_BENCHMARK.'_controller_setup'); - if (Router::$method[0] === '_') - { - // Do not allow access to hidden methods - Event::run('system.404'); - } - // Include the Controller file require Router::$controller_path; @@ -249,6 +243,13 @@ final class Kohana { // Load the controller method $method = $class->getMethod(Router::$method); + // Method exists + if (Router::$method[0] === '_') + { + // Do not allow access to hidden methods + Event::run('system.404'); + } + if ($method->isProtected() or $method->isPrivate()) { // Do not attempt to invoke protected methods @@ -806,126 +807,140 @@ final class Kohana { */ public static function exception_handler($exception, $message = NULL, $file = NULL, $line = NULL) { - // PHP errors have 5 args, always - $PHP_ERROR = (func_num_args() === 5); - - // Test to see if errors should be displayed - if ($PHP_ERROR AND (error_reporting() & $exception) === 0) - return; - - // This is useful for hooks to determine if a page has an error - self::$has_error = TRUE; - - // Error handling will use exactly 5 args, every time - if ($PHP_ERROR) - { - $code = $exception; - $type = 'PHP Error'; - $template = 'kohana_error_page'; - } - else - { - $code = $exception->getCode(); - $type = get_class($exception); - $message = $exception->getMessage(); - $file = $exception->getFile(); - $line = $exception->getLine(); - $template = ($exception instanceof Kohana_Exception) ? $exception->getTemplate() : 'kohana_error_page'; - } - - if (is_numeric($code)) - { - $codes = self::lang('errors'); - - if ( ! empty($codes[$code])) + try + { + // PHP errors have 5 args, always + $PHP_ERROR = (func_num_args() === 5); + + // Test to see if errors should be displayed + if ($PHP_ERROR AND (error_reporting() & $exception) === 0) + return; + + // This is useful for hooks to determine if a page has an error + self::$has_error = TRUE; + + // Error handling will use exactly 5 args, every time + if ($PHP_ERROR) + { + $code = $exception; + $type = 'PHP Error'; + $template = 'kohana_error_page'; + } + else { - list($level, $error, $description) = $codes[$code]; + $code = $exception->getCode(); + $type = get_class($exception); + $message = $exception->getMessage(); + $file = $exception->getFile(); + $line = $exception->getLine(); + $template = ($exception instanceof Kohana_Exception) ? $exception->getTemplate() : 'kohana_error_page'; + } + + if (is_numeric($code)) + { + $codes = self::lang('errors'); + + if ( ! empty($codes[$code])) + { + list($level, $error, $description) = $codes[$code]; + } + else + { + $level = 1; + $error = $PHP_ERROR ? 'Unknown Error' : get_class($exception); + $description = ''; + } } else { - $level = 1; - $error = $PHP_ERROR ? 'Unknown Error' : get_class($exception); + // Custom error message, this will never be logged + $level = 5; + $error = $code; $description = ''; } - } - else - { - // Custom error message, this will never be logged - $level = 5; - $error = $code; - $description = ''; - } - - // Remove the DOCROOT from the path, as a security precaution - $file = str_replace('\\', '/', realpath($file)); - $file = preg_replace('|^'.preg_quote(DOCROOT).'|', '', $file); - - if ($level <= self::$configuration['core']['log_threshold']) - { - // Log the error - self::log('error', self::lang('core.uncaught_exception', $type, $message, $file, $line)); - } - - if ($PHP_ERROR) - { - $description = self::lang('errors.'.E_RECOVERABLE_ERROR); - $description = is_array($description) ? $description[2] : ''; - - if ( ! headers_sent()) + + // Remove the DOCROOT from the path, as a security precaution + $file = str_replace('\\', '/', realpath($file)); + $file = preg_replace('|^'.preg_quote(DOCROOT).'|', '', $file); + + if ($level <= self::$configuration['core']['log_threshold']) { - // Send the 500 header - header('HTTP/1.1 500 Internal Server Error'); + // Log the error + self::log('error', self::lang('core.uncaught_exception', $type, $message, $file, $line)); } - } - else - { - if (method_exists($exception, 'sendHeaders') AND ! headers_sent()) + + if ($PHP_ERROR) { - // Send the headers if they have not already been sent - $exception->sendHeaders(); + $description = self::lang('errors.'.E_RECOVERABLE_ERROR); + $description = is_array($description) ? $description[2] : ''; + + if ( ! headers_sent()) + { + // Send the 500 header + header('HTTP/1.1 500 Internal Server Error'); + } } - } - - while (ob_get_level() > self::$buffer_level) - { - // Close open buffers - ob_end_clean(); - } - - // Test if display_errors is on - if (self::$configuration['core']['display_errors'] === TRUE) - { - if ( ! IN_PRODUCTION AND $line != FALSE) + else { - // Remove the first entry of debug_backtrace(), it is the exception_handler call - $trace = $PHP_ERROR ? array_slice(debug_backtrace(), 1) : $exception->getTrace(); - - // Beautify backtrace - $trace = self::backtrace($trace); + if (method_exists($exception, 'sendHeaders') AND ! headers_sent()) + { + // Send the headers if they have not already been sent + $exception->sendHeaders(); + } } - - // Load the error - require self::find_file('views', empty($template) ? 'kohana_error_page' : $template); - } - else - { - // Get the i18n messages - $error = self::lang('core.generic_error'); - $message = self::lang('core.errors_disabled', url::site(), url::site(Router::$current_uri)); - - // Load the errors_disabled view - require self::find_file('views', 'kohana_error_disabled'); + + while (ob_get_level() > self::$buffer_level) + { + // Close open buffers + ob_end_clean(); + } + + // Test if display_errors is on + if (self::$configuration['core']['display_errors'] === TRUE) + { + if ( ! IN_PRODUCTION AND $line != FALSE) + { + // Remove the first entry of debug_backtrace(), it is the exception_handler call + $trace = $PHP_ERROR ? array_slice(debug_backtrace(), 1) : $exception->getTrace(); + + // Beautify backtrace + $trace = self::backtrace($trace); + } + + // Load the error + require self::find_file('views', empty($template) ? 'kohana_error_page' : $template); + } + else + { + // Get the i18n messages + $error = self::lang('core.generic_error'); + $message = self::lang('core.errors_disabled', url::site(), url::site(Router::$current_uri)); + + // Load the errors_disabled view + require self::find_file('views', 'kohana_error_disabled'); + } + + if ( ! Event::has_run('system.shutdown')) + { + // Run the shutdown even to ensure a clean exit + Event::run('system.shutdown'); + } + + // Turn off error reporting + error_reporting(0); + exit; } - - if ( ! Event::has_run('system.shutdown')) + catch (Exception $e) { - // Run the shutdown even to ensure a clean exit - Event::run('system.shutdown'); + if (IN_PRODUCTION) + { + die('Fatal Error'); + } + else + { + die('Fatal Error: '.$e->getMessage().' File: '.$e->getFile().' Line: '.$e->getLine()); + } } - - // Turn off error reporting - error_reporting(0); - exit; } /** @@ -1027,7 +1042,7 @@ final class Kohana { * * @throws Kohana_Exception if file is required and not found * @param string directory to search in - * @param string filename to look for (including extension only if 4th parameter is TRUE) + * @param string filename to look for (without extension) * @param boolean file required * @param string file extension * @return array if the type is config, i18n or l10n |