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::build();
$error = self::$_values['Error'];
$exception = self::$_values['Exception'];
self::setErrorHandlers(true);
$exception = array(
'handler' => 'ErrorHandler::handleException',
);
$error = array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
);
self::_setErrorHandlers($error, $exception);
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);
}
restore_error_handler();
restore_exception_handler();
self::$_values['Error'] = $error;
self::$_values['Exception'] = $exception;
self::setErrorHandlers();
self::_setErrorHandlers(
self::$_values['Error'],
self::$_values['Exception']
);
unset($error, $exception);
}
}
@ -338,37 +343,23 @@ class Configure {
}
/**
* Sets the configure error and exception handlers.
* If reset is true, sets the cake default error and exception handlers
* Set the 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
* @static
*/
public static function setErrorHandlers($reset = false) {
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
);
}
protected static function _setErrorHandlers($error, $exception) {
$level = -1;
if (isset(self::$_values['Error']['level'])) {
error_reporting(self::$_values['Error']['level']);
$level = self::$_values['Error']['level'];
if (isset($error['level'])) {
error_reporting($error['level']);
$level = $error['level'];
}
if (!empty(self::$_values['Error']['handler'])) {
set_error_handler(self::$_values['Error']['handler'], $level);
if (!empty($error['handler'])) {
set_error_handler($error['handler'], $level);
}
if (!empty(self::$_values['Exception']['handler'])) {
set_exception_handler(self::$_values['Exception']['handler']);
if (!empty($exception['handler'])) {
set_exception_handler($exception['handler']);
}
}
}

View file

@ -354,45 +354,4 @@ class ConfigureTest extends CakeTestCase {
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);
}
}