/**
  * Initialize the error handler
  * @param bool $handle_exceptions [optional]True to handle all exceptions
  * @param bool $handle_errors [optional] True to handle all errors
  * @param bool $debug [optional] True to enable the debug mode, sensitive data will be shown of this mode is enabled
  */
 public static function init($handle_exceptions = true, $handle_errors = true, $debug = false)
 {
     // Set whether the debug mode should be enabled or not
     self::$debug = $debug;
     // Set the error and exception handlers
     if ($handle_errors) {
         set_error_handler(__CLASS__ . '::handleError', E_ALL);
     }
     if ($handle_exceptions) {
         set_exception_handler(__CLASS__ . '::handleException');
     }
     register_shutdown_function(function () {
         $isError = false;
         if ($error = error_get_last()) {
             switch ($error['type']) {
                 case E_ERROR:
                 case E_CORE_ERROR:
                 case E_COMPILE_ERROR:
                 case E_USER_ERROR:
                     $isError = true;
                     ErrorHandler::handleError($error['type'], $error['message'], $error['file'], $error['line'], null);
                     break;
             }
         }
         if ($isError) {
             //var_dump ($error);//do whatever you need with it
         }
     });
 }
Beispiel #2
0
// Make sure Carbon Core is initialized successfully
if (!defined('CARBON_CORE_INIT_DONE') || CARBON_CORE_INIT_DONE != true) {
    die('Failed to load the application because Carbon Core couldn\'t be initialized');
}
// Include the loader for the app and set it up
require_once APP_ROOT . '/autoloader/loader/AppLoader.php';
use app\autoloader\loader\AppLoader;
use app\registry\Registry;
use carbon\core\autoloader\Autoloader;
Autoloader::addLoader(new AppLoader());
// Load the configuration
use app\config\Config;
Config::load();
// Set up the error handler
use carbon\core\ErrorHandler;
ErrorHandler::init(true, true, Config::getValue('app', 'debug'));
// Connect to the database
use app\database\Database;
Database::connect();
// Set up the cookie manager
use carbon\core\cookie\CookieManager;
CookieManager::setCookieDomain(Config::getValue('cookie', 'domain', ''));
CookieManager::setCookiePath(Config::getValue('cookie', 'path', '/'));
CookieManager::setCookiePrefix(Config::getValue('cookie', 'prefix', ''));
// Set up the language manager
use app\language\LanguageManager;
LanguageManager::init(true, Registry::getValue('language.default.tag')->getValue());
$languageTag = LanguageManager::getCookieLanguageTag();
if ($languageTag !== null) {
    LanguageManager::setCurrentLanguageTag($languageTag);
}