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;
}