Renders the source code around the error line.
@param string $file source file path
@param integer $errorLine the error line number
@param integer $maxLines maximum number of lines to display
@return string the rendering result
322284
protected function renderSourceCode($file,$errorLine,$maxLines)
	{
		$errorLine--;	// adjust line number to 0-based from 1-based
		if($errorLine<0 || ($lines=@file($file))===false || ($lineCount=count($lines))<=$errorLine)
			return '';

		$halfLines=(int)($maxLines/2);
		$beginLine=$errorLine-$halfLines>0 ? $errorLine-$halfLines:0;
		$endLine=$errorLine+$halfLines<$lineCount?$errorLine+$halfLines:$lineCount-1;
		$lineNumberWidth=strlen($endLine+1);

		$output='';
		for($i=$beginLine;$i<=$endLine;++$i)
		{
			$isErrorLine = $i===$errorLine;
			$code=sprintf("<span class=\"ln".($isErrorLine?' error-ln':'')."\">%0{$lineNumberWidth}d</span> %s",$i+1,CHtml::encode(str_replace("\t",'    ',$lines[$i])));
			if(!$isErrorLine)
				$output.=$code;
			else
				$output.='<span class="error">'.$code.'</span>';
		}
		return '<div class="code"><pre>'.$output.'</pre></div>';
	}
965355
public function getOption($file, $escapeDigits, $maxTime)
    {
        return $this->playAndRead(implode(' ', array(
            'GET', 'OPTION',
            '"' . $file . '"', '"' . $escapeDigits . '"',
            '"' . $maxTime . '"'
        )));
    }
1193007
public function formatFile($file, $line, $text = null)
    {
        $flags = ENT_QUOTES | ENT_SUBSTITUTE;

        if (null === $text) {
            $file = trim($file);
            $fileStr = $file;
            if (0 === strpos($fileStr, $this->rootDir)) {
                $fileStr = str_replace(['\\', $this->rootDir], ['/', ''], $fileStr);
                $fileStr = htmlspecialchars($fileStr, $flags, $this->charset);
                $fileStr = sprintf('<abbr title="%s">kernel.project_dir</abbr>/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr);
            }

            $text = sprintf('%s at line %d', $fileStr, $line);
        }

        if (false !== $link = $this->getFileLink($file, $line)) {
            return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, $flags, $this->charset), $text);
        }

        return $text;
    }
766318
public static function error_log($errn,$errstr,$file,$line,$context){
		LogMaster::log($errstr." at ".$file." line ".$line);
	}
185041
public function on_error( $num, $str, $file, $line, $context = NULL ) {

		$log_context = [];
		if ( $context ) {
			$skip_keys   = array_merge( array_keys( $GLOBALS ), self::$super_globals_keys );
			$skip        = array_fill_keys( $skip_keys, '' );
			$log_context = array_filter( array_diff_key( (array) $context, $skip ) );
		}

		$log_context[ 'file' ] = $file;
		$log_context[ 'line' ] = $line;

		// Log the PHP error.
		do_action(
			\Inpsyde\Wonolog\LOG,
			new Log( $str, self::$errors_level_map[ $num ], Channels::PHP_ERROR, $log_context )
		);

		return FALSE;
	}
723934
public function errorHandler($code, $message, $file = '', $line = '')
    {
        if ($this->error_to_exception) {

            if (ob_get_length() > 0) {
                ob_end_clean(); // Fix templates
            }

            throw new Exception($message);
        }

        $error = array(
            'code' => $code,
            'file' => $file,
            'line' => $line,
            'message' => $message,
            'backtrace' => $this->log_backtrace ? gplcart_backtrace() : array()
        );

        $print = $this->print_error || !$this->isDb();

        if (in_array($code, $this->getFatalErrorTypes())) {

            if ($print) {
                return false; // Let it fall through to the standard PHP error handler
            }

            $this->log('php_shutdown', $error, 'danger', false);
            return true;
        }

        $key = md5(json_encode($error));

        if (isset($this->errors[$key])) {
            return true;
        }

        $this->errors[$key] = $error;

        if ($print) {
            echo $this->getFormattedError($error);
        }

        $this->log('php_error', $error, 'warning', false);
        return true;
    }
89057
public static function handlePhpError($level, $message, $file, $line)
    {

        // don't want to print suppressed errors
        if (error_reporting() > 0) {
            if (self::$phpErrorCapture) {
                self::$capturedPhpErrors[] = [
                    'message' => $message,
                    'level' => $level,
                    'line' => $line,
                    'file' => $file
                ];
            } else {
                $message = '[PHP Error] ' . $message;
                $message .= ' [line ' . $line . ' of ' . $file . ']';

                switch ($level) {
                    case E_USER_DEPRECATED:
                    case E_DEPRECATED:
                    case E_STRICT:
                    case E_NOTICE:
                    case E_USER_NOTICE:
                        self::log($message, Project::MSG_VERBOSE);
                        break;
                    case E_WARNING:
                    case E_USER_WARNING:
                        self::log($message, Project::MSG_WARN);
                        break;
                    case E_ERROR:
                    case E_USER_ERROR:
                    default:
                        self::log($message, Project::MSG_ERR);
                } // switch
            } // if phpErrorCapture
        } // if not @
    }
388172
private function showErrorMsg(int $httpCode, int $errorCode, string $errorType, string $message, array $traceArr, string $file, int $line)
    {
        if (empty($traceArr)) {
            $traceArr = debug_backtrace();
        }
        $content = $this->getErrContent();
        $mainTitle = 'HTTP 错误 ' . $httpCode;
        $errmsgPrefix = '<span style="color:red;">[' . $errorType . ']</span>[' . $errorCode . '] ';
        $errFile = '<span style="color:red;">[file]</span> ' . $file . ' on line <b>' . $line . '</b>';
        $showSource = Application::$app->config->getValue('ERROR_HANDLER_SHOW_SOURCE');
        $mainSource = '';
        $showMainSourceFn = 'javascript:void(0);';
        if ($showSource) {
            $mainSource = 'filesArr.push(' . json_encode($file) . ');
linesArr.push(' . $line . ');
contentArr.push(' . json_encode(htmlspecialchars(file_get_contents($file))) . ');';
            $showMainSourceFn = 'show_source_main();';
        }
        $content = str_replace([
            '{mainTitle}',
            '{errMsg}',
            '{errFile}',
            '{errTrace}',
            '{prettify.css}',
            '{prettify.js}',
            '{main_source}',
            '{showMainSourceFn}'
        ], [
            $mainTitle,
            $errmsgPrefix . htmlspecialchars($message),
            $errFile,
            $this->getTableHtml($traceArr),
            $showSource ? file_get_contents(Application::$app->mvcSourcePath . '/../static/prettify.css') : '',
            $showSource ? file_get_contents(Application::$app->mvcSourcePath . '/../static/prettify.js') : '',
            $mainSource,
            $showMainSourceFn
        ], $content);
        $actionResult = new ContentResult($content);
        $actionResult->statusCode = $httpCode;
        $actionResult->executeResult();
        exit();
    }
30781
protected function lint($file)
    {
        $command = $this->interpreter == ''
            ? 'php'
            : $this->interpreter;

        if (strpos($command, 'hhvm') !== false) {
            $command .= ' --no-config -l';
        } else {
            if ($this->deprecatedAsError) {
                $command .= ' -d error_reporting=32767 ';
            }

            $command .= ' -n -l ';
        }

        if (!file_exists($file)) {
            throw new BuildException('File not found: ' . $file);
        }

        if (!is_readable($file)) {
            throw new BuildException('Permission denied: ' . $file);
        }

        if ($this->cache) {
            $lastmtime = $this->cache->get($file);

            if ($lastmtime >= filemtime($file)) {
                $this->log("Not linting '" . $file . "' due to cache", Project::MSG_DEBUG);

                return false;
            }
        }

        $messages = [];
        $errorCount = 0;

        exec($command . '"' . $file . '" 2>&1', $messages);

        for ($i = 0, $messagesCount = count($messages); $i < $messagesCount; $i++) {
            $message = $messages[$i];
            if (trim($message) == '') {
                continue;
            }

            if ((!preg_match('/^(.*)Deprecated:/', $message) || $this->deprecatedAsError) && !preg_match(
                '/^No syntax errors detected/',
                $message
            )
            ) {
                $this->log($message, Project::MSG_ERR);

                if (!isset($this->badFiles[$file])) {
                    $this->badFiles[$file] = [];
                }

                $this->badFiles[$file][] = $message;

                $this->hasErrors = true;
                $errorCount++;
            }
        }

        if (!$errorCount) {
            $this->log($file . ': No syntax errors detected', $this->logLevel);

            if ($this->cache) {
                $this->cache->put($file, filemtime($file));
            }
        }
    }
131359
function render($file)
  {
    if(!file_exists(TS3WA_TPL . DS . $file) || !is_readable(TS3WA_TPL . DS . $file))
    {
      throw new Exception("Layout resource not found (" . $file . ")", 404);
    }

    require_once(TS3WA_TPL . DS . $file);
  }
1310755
public function errorHandler($code, $string, $file, $line)
    {

        if (!(error_reporting() & $code))
        {
            return;
        }

        switch ($code)
        {
            case E_USER_ERROR:
                $title = "FATAL ERROR [$code]";
                break;
            case E_USER_WARNING:
                $title = "WARNING";
                break;
            case E_USER_NOTICE:
                $title = "WARNING";
                break;
            default:
                $title = "Unknown Error";
                break;
        }

        $message = "<p style='color:#000;padding:0;margin:0'>"
                . "<span style='border-bottom:1px dashed #000'>$string</span>"
                . " on line $line in file <i>$file</i>"
                . "</p>";
        echo "<div style='color:#920000;border:1px solid #CCC;padding:3px;display:inline-block'>"
        . "<b>{$title}</b><br/>$message"
        . "</div>";
        return true;
    }
626635
protected function renderHtmlExceptionOrError($exception)
    {
        if (!$exception instanceof Exception && !$exception instanceof \Error) {
            throw new RuntimeException("Unexpected type. Expected Exception or Error.");
        }

        $html = sprintf('<div><strong>Type:</strong> %s</div>', get_class($exception));

        if (($code = $exception->getCode())) {
            $html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
        }

        if (($message = $exception->getMessage())) {
            $html .= sprintf('<div><strong>Message:</strong> %s</div>', htmlentities($message));
        }

        if (($file = $exception->getFile())) {
            $html .= sprintf('<div><strong>File:</strong> %s</div>', $file);
        }

        if (($line = $exception->getLine())) {
            $html .= sprintf('<div><strong>Line:</strong> %s</div>', $line);
        }

        if (($trace = $exception->getTraceAsString())) {
            $html .= '<h2>Trace</h2>';
            $html .= sprintf('<pre>%s</pre>', htmlentities($trace));
        }

        return $html;
    }
203958
protected function readLine($file, $lines = 50)
    {
        if (is_file($file) === false) {
            $this->error('tail: cannot open ‘'.$file.'’ for reading: No such file or directory');

            return;
        }

        $fp = fopen($file, 'r');
        $i = 1;
        $result = [];
        while (! feof($fp)) {
            if ($i > $lines) {
                break;
            }
            $content = fgets($fp);
            $result[] = $content;
            $i++;
        }
        fclose($fp);

        $this->line(implode('', $result));
    }
1140337
public function handler($severity, $message, $file, $line)
    {
        throw new ErrorException($message, 0, $severity, $file, $line);
    }
200258
protected function renderErrorAsText($error) {
		$text = sprintf('Type: %s' . PHP_EOL, get_class($error));
	
		if ($code = $error->getCode()) {
			$text .= sprintf('Code: %s' . PHP_EOL, $code);
		}
	
		if ($message = $error->getMessage()) {
			$text .= sprintf('Message: %s' . PHP_EOL, htmlentities($message));
		}
	
		if ($file = $error->getFile()) {
			$text .= sprintf('File: %s' . PHP_EOL, $file);
		}
	
		if ($line = $error->getLine()) {
			$text .= sprintf('Line: %s' . PHP_EOL, $line);
		}
	
		if ($trace = $error->getTraceAsString()) {
			$text .= sprintf('Trace: %s', $trace);
		}
	
		return $text;
	}
519659
public function renderSourceFragment($lines, $errline)
    {
        $output = '<div class="info"><h3>Source</h3>';
        $output .= '<pre>';
        foreach ($lines as $offset => $line) {
            $line = htmlentities($line, ENT_COMPAT, 'UTF-8');
            if ($offset == $errline) {
                $output .= "<span>$offset</span> <span class=\"error\">$line</span>";
            } else {
                $output .= "<span>$offset</span> $line";
            }
        }
        $output .= '</pre></div>';

        return $output;
    }
380527
public function render(string $file = null): string
    {
        if ($file) {
            $this->setFile($file);
        }

        if (empty($this->file)) {
            throw new \Exception('You must set the file to use within your view before rendering');
        }

        return $this->capture($this->file, $this->data, static::$globalData);
    }