Skip to content

Instantly share code, notes, and snippets.

@tPl0ch
Created March 11, 2012 12:51
Show Gist options
  • Save tPl0ch/2016346 to your computer and use it in GitHub Desktop.
Save tPl0ch/2016346 to your computer and use it in GitHub Desktop.
Configure Bootstrap ErrorHandler
<?php
/**
* Initializes configure and runs the bootstrap process.
* Bootstrapping includes the following steps:
*
* - Setup App array in Configure.
* - Include app/Config/core.php.
* - Configure core cache configurations.
* - Load App cache files.
* - Include app/Config/bootstrap.php.
* - Setup error/exception handlers.
*
* @param boolean $boot
* @return void
*/
public static function bootstrap($boot = true) {
if ($boot) {
self::write('App', array(
'base' => false,
'baseUrl' => false,
'dir' => APP_DIR,
'webroot' => WEBROOT_DIR,
'www_root' => WWW_ROOT
));
if (!include APP . 'Config' . DS . 'core.php') {
trigger_error(__d('cake_dev', "Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", APP . 'Config' . DS), E_USER_ERROR);
}
App::$bootstrapping = false;
App::init();
App::build();
self::setErrorHandlers();
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);
}
self::setErrorHandlers();
}
}
/**
* Sets the ErrorHandler and ExceptionHandler to the configured ErrorHandler
* or ExceptionHandler
*
* @return void
* @static
*/
public static function setErrorHandlers() {
$level = -1;
if (isset(self::$_values['Error']['level'])) {
error_reporting(self::$_values['Error']['level']);
$level = self::$_values['Error']['level'];
}
if (!empty(self::$_values['Error']['handler'])) {
set_error_handler(self::$_values['Error']['handler'], $level);
}
if (!empty(self::$_values['Exception']['handler'])) {
set_exception_handler(self::$_values['Exception']['handler']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment