Index: branches/5.3.x/core/kernel/application.php
===================================================================
diff -u -N -r15483 -r15578
--- branches/5.3.x/core/kernel/application.php (.../application.php) (revision 15483)
+++ branches/5.3.x/core/kernel/application.php (.../application.php) (revision 15578)
@@ -1,6 +1,6 @@
Debugger->appendMemoryUsage('Application before Init:');
}
- if ( !$this->isDebugMode() && !kUtil::constOn('DBG_ZEND_PRESENT') ) {
- error_reporting(0);
- ini_set('display_errors', 0);
- }
-
- if ( !kUtil::constOn('DBG_ZEND_PRESENT') ) {
- $error_handler = set_error_handler(Array (&$this, 'handleError'));
- if ( $error_handler ) {
- // wrap around previous error handler, if any was set
- $this->errorHandlers[] = $error_handler;
- }
-
- $exception_handler = set_exception_handler(Array (&$this, 'handleException'));
- if ( $exception_handler ) {
- // wrap around previous exception handler, if any was set
- $this->exceptionHandlers[] = $exception_handler;
- }
- }
-
+ $this->_logger = new kLogger($this->_logger);
$this->Factory = new $factory_class();
$this->registerDefaultClasses();
$vars = kUtil::parseConfig(true);
$db_class = isset($vars['Databases']) ? 'kDBLoadBalancer' : ($this->isDebugMode() ? 'kDBConnectionDebug' : 'kDBConnection');
- $this->Conn = $this->Factory->makeClass($db_class, Array (SQL_TYPE, Array (&$this, 'handleSQLError')));
+ $this->Conn = $this->Factory->makeClass($db_class, Array (SQL_TYPE, Array ($this->_logger, 'handleSQLError')));
$this->Conn->setup($vars);
$this->cacheManager = $this->makeClass('kCacheManager');
@@ -752,6 +726,7 @@
$this->registerClass('kTempTablesHandler', KERNEL_PATH . '/utility/temp_handler.php');
$this->registerClass('kValidator', KERNEL_PATH . '/utility/validator.php');
$this->registerClass('kOpenerStack', KERNEL_PATH . '/utility/opener_stack.php');
+ $this->registerClass('kLogger', KERNEL_PATH . '/utility/logger.php');
$this->registerClass('kUnitConfigReader', KERNEL_PATH . '/utility/unit_config_reader.php');
@@ -2385,224 +2360,15 @@
* @param string $sql
* @return bool
* @access public
+ * @throws Exception
+ * @deprecated
*/
public function handleSQLError($code, $msg, $sql)
{
- if ( isset($this->Debugger) ) {
- $long_error_msg = '' . $msg . ' (' . $code . ')
SQL: ' . $this->Debugger->formatSQL($sql);
- $long_id = $this->Debugger->mapLongError($long_error_msg);
- $error_msg = mb_substr($msg . ' (' . $code . ') [' . $sql . ']', 0, 1000) . ' #' . $long_id;
-
- if ( kUtil::constOn('DBG_SQL_FAILURE') && !defined('IS_INSTALL') ) {
- throw new Exception($error_msg);
- }
- else {
- $this->Debugger->appendTrace();
- }
- }
- else {
- // when not debug mode, then fatal database query won't break anything
- $error_msg = 'SQL Error in sql: ' . $sql . ', code ' . $code . ' (' . $msg . ')';
- }
-
- trigger_error($error_msg, E_USER_WARNING);
-
- return true;
+ return $this->_logger->handleSQLError($code, $msg, $sql);
}
/**
- * Default error handler
- *
- * @param int $errno
- * @param string $errstr
- * @param string $errfile
- * @param int $errline
- * @param Array $errcontext
- * @return bool
- * @access public
- */
- public function handleError($errno, $errstr, $errfile = null, $errline = null, $errcontext = Array ())
- {
- $this->errorLogSilent($errno, $errstr, $errfile, $errline);
-
- $debug_mode = defined('DEBUG_MODE') && DEBUG_MODE;
- $skip_reporting = defined('DBG_SKIP_REPORTING') && DBG_SKIP_REPORTING;
-
- if ( !$this->errorHandlers || ($debug_mode && $skip_reporting) ) {
- // when debugger absent OR it's present, but we actually can't see it's error report (e.g. during ajax request)
- if ( $errno == E_USER_ERROR ) {
- $this->errorDisplayFatal('Fatal Error: ' . "{$errstr} in {$errfile} on line {$errline}");
- }
-
- if ( !$this->errorHandlers ) {
- return true;
- }
- }
-
- $res = false;
- /* @var $handler Closure */
-
- foreach ($this->errorHandlers as $handler) {
- if ( is_array($handler) ) {
- $object =& $handler[0];
- $method = $handler[1];
- $res = $object->$method($errno, $errstr, $errfile, $errline, $errcontext);
- }
- else {
- $res = $handler($errno, $errstr, $errfile, $errline, $errcontext);
- }
- }
-
- return $res;
- }
-
- /**
- * Handles exception
- *
- * @param Exception $exception
- * @return bool
- * @access public
- */
- public function handleException($exception)
- {
- // transform exception to regular error (no need to rewrite existing error handlers)
- $errno = $exception->getCode();
- $errstr = $exception->getMessage();
- $errfile = $exception->getFile();
- $errline = $exception->getLine();
-
- $this->errorLogSilent($errno, $errstr, $errfile, $errline);
-
- $debug_mode = defined('DEBUG_MODE') && DEBUG_MODE;
- $skip_reporting = defined('DBG_SKIP_REPORTING') && DBG_SKIP_REPORTING;
-
- if ( $exception instanceof kRedirectException ) {
- /* @var $exception kRedirectException */
-
- $exception->run();
- }
-
- if ( !$this->exceptionHandlers || ($debug_mode && $skip_reporting) ) {
- // when debugger absent OR it's present, but we actually can't see it's error report (e.g. during ajax request)
- $this->errorDisplayFatal('' . get_class($exception) . ': ' . "{$errstr} in {$errfile} on line {$errline}");
-
- if ( !$this->exceptionHandlers ) {
- return true;
- }
- }
-
- $res = false;
- /* @var $handler Closure */
-
- foreach ($this->exceptionHandlers as $handler) {
- if ( is_array($handler) ) {
- $object =& $handler[0];
- $method = $handler[1];
- $res = $object->$method($exception);
- }
- else {
- $res = $handler($exception);
- }
- }
-
- return $res;
- }
-
- /**
- * Silently saves each given error message to "silent_log.txt" file, when silent log mode is enabled
- * @param int $errno
- * @param string $errstr
- * @param string $errfile
- * @param int $errline
- * @return void
- * @access protected
- */
- protected function errorLogSilent($errno, $errstr = '', $errfile = '', $errline = null)
- {
- if ( !defined('SILENT_LOG') || !SILENT_LOG ) {
- return;
- }
-
- if ( !(defined('DBG_IGNORE_STRICT_ERRORS') && DBG_IGNORE_STRICT_ERRORS && defined('E_STRICT') && ($errno == E_STRICT)) ) {
- $time = adodb_date('d/m/Y H:i:s');
-
- $fp = fopen((defined('RESTRICTED') ? RESTRICTED : FULL_PATH) . '/silent_log.txt', 'a');
- fwrite($fp, '[' . $time . '] #' . $errno . ': ' . strip_tags($errstr) . ' in [' . $errfile . '] on line ' . $errline . "\n");
- fclose($fp);
- }
- }
-
- /**
- * Displays div with given error message
- *
- * @param string $msg
- * @return void
- * @access protected
- */
- protected function errorDisplayFatal($msg)
- {
- $margin = $this->isAdmin ? '8px' : 'auto';
- echo '