Пример #1
0
function phpErrorHandler($severity, $message, $filename, $lineno)
{
    switch ($severity) {
        case E_ERROR:
        case E_WARNING:
        case E_PARSE:
        case E_CORE_ERROR:
        case E_COMPILE_WARNING:
        case E_USER_WARNING:
            if (LOGGING) {
                Log::logException(LoggingConstants::ERROR, "Unexpected error", ErrorException($message, 0, $severity, $filename, $lineno));
            }
            break;
        case E_RECOVERABLE_ERROR:
        case E_USER_ERROR:
            $exception = new ErrorException($message, 0, $severity, $filename, $lineno);
            if (LOGGING) {
                Log::logException(LoggingConstants::ERROR, "Unexpected error", $exception);
            }
            throw $exception;
            break;
        case E_USER_NOTICE:
        case E_NOTICE:
            if (LOGGING) {
                Log::log(LoggingConstants::INFO, "PHP notice: {$message}, file:{$filename}, line:{$lineno}");
            }
            break;
        default:
            if (LOGGING) {
                Log::log(LoggingConstants::DEBUG, "PHP notice: {$message}, file:{$filename}, line:{$lineno}");
            }
    }
}
Пример #2
0
 public static function init()
 {
     if (!ob_start(function ($buffer) {
         $tidy = new \tidy();
         return $tidy->repairString($buffer, ['input-xml' => true, 'indent' => true, 'wrap' => 0, 'output-xml' => true]);
     })) {
         throw \ErrorException("ob_start failed", null, null, __FILE__, __LINE__);
     }
 }
Пример #3
0
 public static function init()
 {
     if (!ob_start(function ($buffer) {
         $xslt = new \WebConstructionSet\ContentModifier\Xslt(dirname($_SERVER['SCRIPT_FILENAME']) . '/');
         $xslt->process($buffer);
         return $xslt->getHtml();
     })) {
         throw \ErrorException("ob_start failed", null, null, __FILE__, __LINE__);
     }
 }
Пример #4
0
 public function make($flag)
 {
     if (!isset($this->trusts[$flag])) {
         $trustClass = 'sysuser_plugin_' . $flag;
         if (!class_exists($trustClass)) {
             throw \ErrorException("class {$trustClass} not exists.");
         }
         $this->trusts[$flag] = kernel::single($trustClass);
     }
     return $this->trusts[$flag];
 }
Пример #5
0
 /**
  * @param string - $sql
  * @param array|mixed - sql params [optional]
  * @param Closure
  * @return number of rows processed
  * 
  * @example
  *	$db->eachRow('show tables', 'print_r');
  *
  * @example
  * 	$db->eachRow("show tables like ? ", "%wap_%", function ($it) {
  *		print_r($it);
  *	});
  * 
  * @example
  *	$db->eachRow("select concat(?, ?, ?)", '100',' + ', '200', 'var_dump');
  */
 public function eachRow($sql, $func)
 {
     $args = func_get_args();
     $sql = array_shift($args);
     $func = array_pop($args);
     if (!is_callable($func)) {
         throw ErrorException('Invalid last argument type. It should be callable.');
     }
     $n = 0;
     foreach ($this->query($sql, $args, Database::FETCH_OBJ) as $it) {
         call_user_func($func, $it);
         $n++;
     }
     return $n;
 }