public static function excerpt($file, $line, $context = 2)
    {
        $lines = [];
        if (!file_exists($file)) {
            return [];
        }
        $data = file_get_contents($file);
        if (empty($data)) {
            return $lines;
        }
        if (strpos($data, "\n") !== false) {
            $data = explode("\n", $data);
        }
        $line--;
        if (!isset($data[$line])) {
            return $lines;
        }
        for ($i = $line - $context; $i < $line + $context + 1; $i++) {
            if (!isset($data[$i])) {
                continue;
            }
            $string = str_replace(["\r\n", "\n"], '', static::_highlight($data[$i]));
            if ($i == $line) {
                $lines[] = '<span class="code-highlight">' . $string . '</span>';
            } else {
                $lines[] = $string;
            }
        }

        return $lines;
    }
public static function excerpt($file, $line, $context = 2)
    {
        $lines = [];
        if (!file_exists($file)) {
            return [];
        }
        $data = file_get_contents($file);
        if (empty($data)) {
            return $lines;
        }
        if (strpos($data, "\n") !== false) {
            $data = explode("\n", $data);
        }
        $line--;
        if (!isset($data[$line])) {
            return $lines;
        }
        for ($i = $line - $context; $i < $line + $context + 1; $i++) {
            if (!isset($data[$i])) {
                continue;
            }
            $string = str_replace(["\r\n", "\n"], '', static::_highlight($data[$i]));
            if ($i == $line) {
                $lines[] = '<span class="code-highlight">' . $string . '</span>';
            } else {
                $lines[] = $string;
            }
        }

        return $lines;
    }
public static function excerpt ( $ file , $ line , $ context = 2 ) { $ lines = [ ] ; if ( ! file_exists ( $ file ) ) { return [ ] ; } $ data = file_get_contents ( $ file ) ; if ( empty ( $ data ) ) { return $ lines ; } if ( strpos ( $ data , "\n" ) !== false ) { $ data = explode ( "\n" , $ data ) ; } $ line -- ; if ( ! isset ( $ data [ $ line ] ) ) { return $ lines ; } for ( $ i = $ line - $ context ; $ i < $ line + $ context + 1 ; $ i ++ ) { if ( ! isset ( $ data [ $ i ] ) ) { continue ; } $ string = str_replace ( [ "\r\n" , "\n" ] , '' , static :: _highlight ( $ data [ $ i ] ) ) ; if ( $ i == $ line ) { $ lines [ ] = '<span class="code-highlight">' . $ string . '</span>' ; } else { $ lines [ ] = $ string ; } } return $ lines ; }
Grabs an excerpt from a file and highlights a given line of code.

Usage:

```
Debugger::excerpt('/path/to/file', 100, 4);
```

The above would return an array of 8 items. The 4th item would be the provided line,
and would be wrapped in `<span class="code-highlight"></span>`. All of the lines
are processed with highlight_string() as well, so they have basic PHP syntax highlighting
applied.

@param string $file Absolute path to a PHP file.
@param int $line Line number to highlight.
@param int $context Number of lines of context to extract above and below $line.
@return array Set of lines highlighted
@see https://secure.php.net/highlight_string
@link https://book.cakephp.org/3.0/en/development/debugging.html#getting-an-excerpt-from-a-file
Grabs an excerpt from a file and highlights a given line of code .