Esempio n. 1
0
 /**
  * @param string $section - error section. I.e. Entry controller
  * @param string $msg - main message
  * @param int $type - error type
  * @param int $code - error code
  * @param int $line - file line
  * @param string $file - file name
  * @param null $sMsg
  * @internal param string $smsg - additional message
  * @return null
  */
 public static function Error($section, $msg, $type = SPC::NOTICE, $code = 0, $line = null, $file = null, $sMsg = null)
 {
     if ($type == 0) {
         $type = SPC::NOTICE;
     }
     /*
      * Mi., Jul 4, 2012
      * So now could someone explain me what was the sense of the code below and why trigger_error was commented out??!!
      *
      * Mi., Jul 4, 2012
      * Ok, it doesn't make much sense.
      * This is what actually should be removed.
      * 		if( Sobi::Cfg( 'debug.level', 0 ) < $type ) { return true; }
      * It was the problem with the ACL when error reporting was disabled.
      * But why the hell I removed the damn trigger_error from it?!!!
      * Being sloppy again?!!!!
      * Frack me - it means that since 20.07.2011 the whole error reporting went in nirvana??
      */
     if ($type == E_USER_ERROR) {
         $rType = E_ERROR;
         $code = $code ? $code : 500;
     } elseif ($type == E_USER_WARNING) {
         $rType = E_WARNING;
     } else {
         $rType = $type;
     }
     if (Sobi::Cfg('debug.level', 0) >= $rType) {
         if ($file) {
             $sMsg .= sprintf('In file %s at line %d', $file, $line);
         }
         if (SPRequest::task()) {
             $sMsg .= ' [ ' . SPRequest::task() . ' ]';
         }
         $error = array('section' => $section, 'message' => $msg, 'code' => $code, 'file' => $file, 'line' => $line, 'content' => $sMsg);
         trigger_error('json://' . json_encode($error), $type);
     }
     if ($code) {
         SPLoader::loadClass('base.mainframe');
         SPLoader::loadClass('cms.base.mainframe');
         SPFactory::mainframe()->runAway($msg, $code, SPConfig::getBacktrace());
     }
     return null;
 }
Esempio n. 2
0
 /**
  *
  * @param int $errNumber
  * @param string $errString
  * @param string $errFile
  * @param int $errLine
  * @param string $errContext
  * @throws ErrorException
  * @throws Exception
  * @throws SPException
  * @return bool
  */
 function SPExceptionHandler($errNumber, $errString, $errFile, $errLine, $errContext)
 {
     if ($errNumber == E_STRICT && (!defined('SOBI_TESTS') || !SOBI_TESTS)) {
         return true;
     }
     $error = null;
     if (!strstr($errFile, 'sobipro')) {
         return false;
     }
     static $cs = 0;
     if ($cs > 100) {
         echo '<h1>Error handler: Violation of critical section. Possible infinite loop. Error reporting temporary disabled. ' . $errString . '</h1>';
         $cs = 0;
         return false;
     }
     if (!class_exists('SPLoader')) {
         /** @noinspection PhpIncludeInspection */
         require_once SOBI_PATH . '/lib/base/fs/loader.php';
     }
     if (strstr($errString, 'json://')) {
         $error = json_decode(str_replace('json://', null, $errString), true);
     }
     if (ini_get('error_reporting') < $errNumber && !(isset($error['code']) && $error['code'])) {
         $cs = 0;
         return false;
     }
     $backTrace = null;
     if (class_exists('SPConfig')) {
         $backTrace = SPConfig::getBacktrace();
     }
     if ($error) {
         $retCode = $error['code'];
         $errString = $error['message'];
         $errFile = $error['file'];
         $errLine = $error['line'];
         $section = $error['section'];
         $errContext = $error['content'];
     } else {
         $retCode = 0;
         if (!strstr($errFile, 'sobi')) {
             $cs = 0;
             return false;
         }
         /* stupid errors we already handle
          * and there is no other possibility to catch it
          * before it happens
          */
         if (strstr($errString, 'gzinflate')) {
             $cs = 0;
             return false;
         }
         if (strstr($errString, 'compress')) {
             $cs = 0;
             return false;
         }
         if (strstr($errString, 'domdocument.loadxml')) {
             $cs = 0;
             return false;
         }
         /** This really sucks - why do I have the possibility to override a method when I cannot change its parameters :(
          * A small design flaw - has to be changed later */
         if (strstr($errString, 'should be compatible with')) {
             $cs = 0;
             return false;
         }
         /* output of errors / call stack causes sometimes it - it's not really important */
         if (strstr($errString, 'Property access is not allowed yet')) {
             $cs = 0;
             return false;
         }
         $section = 'PHP';
     }
     $cs++;
     SPException::storeError($errNumber, $retCode, $errString, $errFile, $errLine, $section, $errContext, $backTrace);
     if ($retCode) {
         SPLoader::loadClass('base.mainframe');
         SPLoader::loadClass('cms.base.mainframe');
         SPFactory::mainframe()->runAway($errString, $retCode, $backTrace);
     } else {
         if ($errNumber == E_USER_ERROR || $errNumber == E_ERROR) {
             throw new ErrorException($errString, $retCode, $errNumber, $errFile, $errLine);
         }
     }
     $cs = 0;
     /** do not display our internal errors because this is an array */
     if ($error) {
         return true;
     }
     return false;
 }