Kint::_showSource PHP Метод

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

trace helper, shows the place in code inline
private static _showSource ( string $file, integer $lineNumber, integer $padding = 7 ) : boolean | string
$file string full path to file
$lineNumber integer the line to display
$padding integer surrounding lines to show besides the main one
Результат boolean | string
    private static function _showSource($file, $lineNumber, $padding = 7)
    {
        if (!$file or !is_readable($file)) {
            # continuing will cause errors
            return false;
        }
        # open the file and set the line position
        $file = fopen($file, 'r');
        $line = 0;
        # Set the reading range
        $range = array('start' => $lineNumber - $padding, 'end' => $lineNumber + $padding);
        # set the zero-padding amount for line numbers
        $format = '% ' . strlen($range['end']) . 'd';
        $source = '';
        while (($row = fgets($file)) !== false) {
            # increment the line number
            if (++$line > $range['end']) {
                break;
            }
            if ($line >= $range['start']) {
                # make the row safe for output
                $row = htmlspecialchars($row, ENT_NOQUOTES, 'UTF-8');
                # trim whitespace and sanitize the row
                $row = '<span>' . sprintf($format, $line) . '</span> ' . $row;
                if ($line === $lineNumber) {
                    # apply highlighting to this row
                    $row = '<div class="kint-highlight">' . $row . '</div>';
                } else {
                    $row = '<div>' . $row . '</div>';
                }
                # add to the captured source
                $source .= $row;
            }
        }
        # close the file
        fclose($file);
        return $source;
    }