Make method protected.

API changes should be minimized in bug fix releases.
Fix broken builds.
This commit is contained in:
mark_story 2012-03-16 21:46:07 -04:00
parent 381e5b10bc
commit 8fdd57568b
2 changed files with 23 additions and 73 deletions

View file

@ -76,19 +76,24 @@ class Configure {
App::init(); App::init();
App::build(); App::build();
$error = self::$_values['Error']; $exception = array(
$exception = self::$_values['Exception']; 'handler' => 'ErrorHandler::handleException',
self::setErrorHandlers(true); );
$error = array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
);
self::_setErrorHandlers($error, $exception);
if (!include APP . 'Config' . DS . 'bootstrap.php') { if (!include APP . 'Config' . DS . 'bootstrap.php') {
trigger_error(__d('cake_dev', "Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", APP . 'Config' . DS), E_USER_ERROR); trigger_error(__d('cake_dev', "Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", APP . 'Config' . DS), E_USER_ERROR);
} }
restore_error_handler(); restore_error_handler();
restore_exception_handler();
self::$_values['Error'] = $error; self::_setErrorHandlers(
self::$_values['Exception'] = $exception; self::$_values['Error'],
self::setErrorHandlers(); self::$_values['Exception']
);
unset($error, $exception); unset($error, $exception);
} }
} }
@ -338,37 +343,23 @@ class Configure {
} }
/** /**
* Sets the configure error and exception handlers. * Set the error and exception handlers.
* If reset is true, sets the cake default error and exception handlers
* *
* @param boolean $reset True if the cake default error handlers should be set * @param array $error The Error handling configuration.
* @param array $exception The exception handling configuration.
* @return void * @return void
* @static
*/ */
public static function setErrorHandlers($reset = false) { protected static function _setErrorHandlers($error, $exception) {
if (true === $reset) {
self::$_values['Exception'] = array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'ExceptionRenderer',
'log' => true
);
self::$_values['Error'] = array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
);
}
$level = -1; $level = -1;
if (isset(self::$_values['Error']['level'])) { if (isset($error['level'])) {
error_reporting(self::$_values['Error']['level']); error_reporting($error['level']);
$level = self::$_values['Error']['level']; $level = $error['level'];
} }
if (!empty(self::$_values['Error']['handler'])) { if (!empty($error['handler'])) {
set_error_handler(self::$_values['Error']['handler'], $level); set_error_handler($error['handler'], $level);
} }
if (!empty(self::$_values['Exception']['handler'])) { if (!empty($exception['handler'])) {
set_exception_handler(self::$_values['Exception']['handler']); set_exception_handler($exception['handler']);
} }
} }
} }

View file

@ -354,45 +354,4 @@ class ConfigureTest extends CakeTestCase {
Configure::config('test', $reader); Configure::config('test', $reader);
} }
/**
* Tests that resetting the ErrorHandlers works as expected
*
* @return void
*/
public function testSetErrorHandlers() {
$error = array(
'handler' => 'ErrorHandler::handleError',
'level' => -2000,
'trace' => false
);
$exception = array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'MyExceptionRenderer',
'log' => false
);
Configure::write('Error', $error);
Configure::setErrorHandlers(true);
$expected = array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
);
$this->assertEqual(Configure::read('Error'), $expected);
$expected = array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'ExceptionRenderer',
'log' => true
);
$this->assertEqual(Configure::read('Exception'), $expected);
Configure::write('Error', $error);
Configure::write('Exception', $exception);
Configure::setErrorHandlers();
$this->assertEqual(Configure::read('Error'), $error);
$this->assertEqual(Configure::read('Exception'), $exception);
}
} }