Render a fragment of the a source file

@param array $lines An array of file lines; the keys should be the original line numbers
@param int $errline The line of the error
@return string
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;
    }
1069115
public function renderError($httpRequest, $errno, $errstr, $errfile, $errline)
    {
        if (!isset(self::$error_types[$errno])) {
            $errorTypeTitle = "UNKNOWN TYPE, ERRNO $errno";
        } else {
            $errorTypeTitle = self::$error_types[$errno]['title'];
        }
        $output = CLI::text("ERROR [" . $errorTypeTitle . "]: $errstr\nIN $httpRequest\n", "red", null, true);
        $output .= CLI::text("Line $errline in $errfile\n\n", "red");

        return $output;
    }
611618
public function handle($errno, $errstr, $errfile, $errline)
    {
        if (!$this->processorsStack) {
            return null;
        }

        foreach ($this->processorsStack as $processor) {
            if (!($processor->getErrorTypes() & $errno)) {
                continue;
            }

            $lastResult = $processor->handle($errno, $errstr, $errfile, $errline);
        }

        return isset($lastResult) ? $lastResult : null;
    }
276454
static public function errorHandler($errno, $errstr, $errfile='', $errline=0, $errcontext=array())
    {
        if (!isset(self::$ignore[basename($errfile) . '-' . $errline . '-' . $errno])) {
            $msg = $errstr . ' Line '
                    . $errline
                    . ', '
                    . $errfile;
            self::$logger->debug($msg);
        }

        return true;
    }
734632
public function renderLines(array $codes, $newLine = true, $eolLine = true)
    {
        $result = '';
        $count = count($codes);

        for ($index = 0; $index < $count; ++$index) {
            $result .= $this->renderLine($codes[$index], $newLine && $index !== $count - 1);
        }

        return $this->renderLine($result, $eolLine);
    }
322313
private function toString($lines = null): string
    {
        // empty path return empty string
        if ($lines === null || count($lines) === 0) {
            return '';
        }

        return implode(
            ' ',
            array_map(
                function ($arg) {
                    return self::quoteArgument($arg, $this->escape);
                },
                $lines
            )
        );
    }
497981
public static function handlerError($errno, $errstr, $errfile, $errline)
    {
        $bad = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR);

        // set log file name
        switch ($errno) {
            case E_ERROR:             $fn = "error";                 break;
            case E_WARNING:           $fn = "warning";               break;
            case E_PARSE:             $fn = "parse";                 break;
            case E_NOTICE:            $fn = "notice";                break;
            case E_CORE_ERROR:        $fn = "core_error";            break;
            case E_CORE_WARNING:      $fn = "core_warning";          break;
            case E_COMPILE_ERROR:     $fn = "compile_error";         break;
            case E_COMPILE_WARNING:   $fn = "compile_warning";       break;
            case E_USER_ERROR:        $fn = "user_error";            break;
            case E_USER_WARNING:      $fn = "user_warning";          break;
            case E_USER_NOTICE:       $fn = "user_notice";           break;
            case E_STRICT:            $fn = "strict";                break;
            case E_RECOVERABLE_ERROR: $fn = "recoverable_error";     break;
            case E_DEPRECATED:        $fn = "deprecated";            break;
            case E_USER_DEPRECATED:   $fn = "user_deprecated";       break;
            case E_ALL:               $fn = "all";                   break;
            default:                  $fn = "__{$errno}__undefined"; break;
        }

        if(defined('PATH_ROOT')) {
            $errfile = str_replace(realpath(PATH_ROOT), '', $errfile);
        }

        $err_msg = strtoupper($fn) . ": {$errstr}\nLINE: {$errline}\nFILE: {$errfile}";

        // With this setup errors are displayed according to the error_reporting() setting
        // but all errors are logged to file, regardles of
        if(defined('DEBUG') && DEBUG && error_reporting() & $errno) {
            echo self::_skipFormating()
                ? $err_msg . PHP_EOL
                : sprintf("<pre>\n<p style='%s'>\n%s\n</p>\n</pre>\n\n", self::getFormattedCss(), $err_msg);
        }

        // all errors are logged
        if(!empty($fn)) {
            self::_writeLog($fn . self::$_extenstion, $err_msg);
            self::_writeLogJson($fn, $errstr, $errno, $errline, $errfile, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
        }

        // On production setup, if bad errors occurs, send mail with parsed exception and terminate the script
        // DISABLED FOR NOW SINCE IT'S KILLING US AT THE MOMENT!!!!!
        // SWITCH TO EVENTS!!!!!
//         if(in_array($errno, $bad)) {
//             if(defined('DEBUG') && !DEBUG) {
//                 try {
//                     throw new \Exception($errstr);
//                 } catch (\Exception $e) {
//                     $msg = self::_parseException($e);
//                 }

//                 defined('EMAIL_DEBUG')
//                 && defined('EMAIL_DEBUG_FROM')
//                 && @mail (EMAIL_DEBUG, "PHP ERROR: {$errstr}", $msg, 'From: ' . EMAIL_DEBUG_FROM);
//             }
//             exit(1);
//         }
    }
82701
public function renderLayout(array $data = null)
    {
        !$data or extract($data);
        ob_start();

        /** @noinspection PhpIncludeInspection */
        if (file_exists(rtrim(
                $this->getLayoutPath(), $this->getFileExt()
            ) . $this->getFileExt())) {

            include rtrim(
                    $this->getLayoutPath(), $this->getFileExt()
                ) . $this->getFileExt();

        } elseif (file_exists(rtrim(
                $this->getLayoutFallbackPath(), $this->getFileExt()
            ) . $this->getFileExt())) {

            include rtrim(
                    $this->getLayoutFallbackPath(), $this->getFileExt()
                ) . $this->getFileExt();
        } else {

            throw new ViewNotFoundException('View ' . rtrim(
                    $this->getLayoutPath(), $this->getFileExt()
                ) . $this->getFileExt() . ' not found');
        }

        $rendered = ob_get_contents();
        ob_end_clean();

        return $rendered;
    }
940528
private function renderDiff($lines1, $lines2)
    {
        if (!is_array($lines1)) {
            $lines1 = explode("\n", $lines1);
        }
        if (!is_array($lines2)) {
            $lines2 = explode("\n", $lines2);
        }
        foreach ($lines1 as $i => $line) {
            $lines1[$i] = rtrim($line, "\r\n");
        }
        foreach ($lines2 as $i => $line) {
            $lines2[$i] = rtrim($line, "\r\n");
        }

        $renderer = new DiffRendererHtmlInline();
        $diff = new \Diff($lines1, $lines2);

        return $diff->render($renderer);
    }
126526
public function render(
        $content,
        array $attribs = [],
        ElementInterface $element = null,
        FormInterface $form = null
    ) {
        $legendHelper = $this->getLegendHelper();

        if ($legendHelper instanceof TranslatorAwareInterface) {
            $rollbackTextDomain = $legendHelper->getTranslatorTextDomain();
            $legendHelper->setTranslatorTextDomain($this->getTranslatorTextDomain());
        }

        $content = $legendHelper(
                $element,
                [],
                $element,
                $form
            ) . $content;

        if (isset($rollbackTextDomain)) {
            $legendHelper->setTranslatorTextDomain($rollbackTextDomain);
        }

        return parent::render($content, $attribs);
    }
133530
private function renderRequiredFilesLines()
    {
        $code = array();
        $indentation = $this->getIndentation();
        foreach ($this->requiredFiles as $requiredFile) {
            $code[] = $indentation . "require_once ('" . $requiredFile . "');";
        }

        if (count($this->requiredFiles) > 0) {
            $code[] = null;
        }

        return $code;
    }
1320214
public function callback($errno, $errstr, $errfile = '', $errline = 0, $errcontext = [])
    {
        $this->log[(string)microtime(true)] = [
            'no' => $errno,
            'str' => $errstr,
            'file' => $errfile,
            'line' => $errline,
            'context' => $errcontext,
        ];
        return $this->handle();
    }
979176
private function handleMustacheErrors($errno, $errstr, $errfile, $errline)
    {
        if (!empty($this->lastTemplate)) {
            if (function_exists('newrelic_add_custom_parameter')) {
                call_user_func(
                    'newrelic_add_custom_parameter',
                    'contactclientToken',
                    $this->lastTemplate
                );
            }
        }
        if (!empty($this->context)) {
            if (function_exists('newrelic_add_custom_parameter')) {
                call_user_func(
                    'newrelic_add_custom_parameter',
                    'contactclientContext',
                    json_encode($this->context)
                );
            }
        }
        $this->logger->error(
            'Contact Client '.$this->contactClient->getId().
            ': Warning issued with Template: '.$this->lastTemplate.' Context: '.json_encode($this->context)
        );

        return true;
    }
1294176
protected function buildErrorTrace($errfile, $errline)
    {
        if ($this->captureErrorStacktraces) {
            $backTrace = $this->fetchErrorTrace();
            
            $backTrace = $this->stripShutdownFrames($backTrace);
            
            // Add the final frame
            array_unshift(
                $backTrace,
                array('file' => $errfile, 'line' => $errline)
            );
        } else {
            $backTrace = array();
        }
        
        return $backTrace;
    }
320715
public static function errorToException($errno, $errstr, $errfile, $errline)
    {
        $exclude = E_STRICT | E_NOTICE | E_USER_NOTICE;
        if (((error_reporting() & $errno) != $errno) || (($exclude & $errno) == $errno)) {
            return false;
        }

        $constants = get_defined_constants(true);
        $name = 'Unknown PHP Error (' . $errno . ')';
        foreach ($constants['Core'] as $c => $value) {
            if ((substr($c, 0, 2) != 'E_') || ($value != $errno)) {
                continue;
            }

            $name = 'PHP ' . ucwords(str_replace('_', ' ', strtolower(substr($c, 2))));
        }

        $exception = new \RuntimeException(sprintf('%s: %s in %s on line %d', $name, $errstr, $errfile, $errline), $errno);

        // Impossible to throw an exception without stack trace
        // happens when errors occour in shutdown scope (i.e. serialize handler)
        if (count($exception->getTrace()) < 1) {
            return false;
        }

        throw $exception;
    }
851836
public static function log_error($errno, $errstr, $errfile, $errline){
    if ( \defined('BBN_DATA_PATH') ){
      if ( is_dir(BBN_DATA_PATH.'logs') ){
        $file = BBN_DATA_PATH.'logs/_php_error.json';
        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20);
        $r = false;
        if ( is_file($file) ){
          $r = json_decode(file_get_contents($file), 1);
        }
        if ( !$r ){
          $r = [];
        }
        $t = date('Y-m-d H:i:s');
        if ( class_exists('\\bbn\\mvc') ){
          $mvc = mvc::get_instance();
        }
        $idx = self::find($r, [
          'type' => $errno,
          'error' => $errstr,
          'file' => $errfile,
          'line' => $errline,
          'request' => ''
        ]);
        if ( $idx !== false ){
          $r[$idx]['count']++;
          $r[$idx]['last_date'] = $t;
          $r[$idx]['backtrace'] = $backtrace;
        }
        else{
          $r[] = [
            'first_date' => $t,
            'last_date' => $t,
            'count' => 1,
            'type' => $errno,
            'error' => $errstr,
            'file' => $errfile,
            'line' => $errline,
            'backtrace' => $backtrace,
            'request' => ''
            //'context' => $context
          ];
        }
        self::sort_by($r, 'last_date', 'DESC');
        file_put_contents($file, json_encode($r, JSON_PRETTY_PRINT));
      }
      if ( $errno > 8 ){
        die($errstr);
      }
    }
    return false;
  }
1133100
protected function jump($errcode=null, $errmsg=null, $data=null)
    {
        $this->stop();
        
        $renderType = $this->getRenderType();
        
        $this->errorInfo  = ErrorInfo::instance($errcode, $errmsg, $data);
        
        if ($renderType === 'json') {
            return $this->renderJson($this->errorInfo);
        } else {
            return $this->renderMessageBox($this->errorInfo);
        }
    }