PDO4You\PDO4You::highlightSource PHP Метод

highlightSource() приватный статический Метод

Method to highlight the syntax of a code
Автор: Marcus Welz
private static highlightSource ( string $fileName, string $lineNumber, string $showLines = 5 ) : string
$fileName string Filename
$lineNumber string Sets the highlighted row
$showLines string Sets the number of rows to display
Результат string
    private static function highlightSource($fileName, $lineNumber, $showLines = 5)
    {
        $offset = max(0, $lineNumber - ceil($showLines / 2));
        $lines = file_get_contents($fileName);
        $lines = highlight_string($lines, true);
        $lines = array_slice(explode('<br />', $lines), $offset, $showLines);
        $count = count($lines);
        for ($i = $count; $i < $showLines; $i++) {
            array_push($lines, '&nbsp;');
        }
        $trace = null;
        foreach ($lines as $line) {
            $offset++;
            $trace .= '<div' . ($offset == $lineNumber ? ' class="highlight"' : '') . '><span class="number">' . sprintf('%4d', $offset) . '</span>' . $line . '</div>';
        }
        return $trace;
    }