| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | namespace Kint\Renderer\Rich; |
| 27: | |
| 28: | use Kint\Object\Representation\Representation; |
| 29: | use Kint\Object\Representation\SourceRepresentation; |
| 30: | |
| 31: | class SourcePlugin extends Plugin implements TabPluginInterface |
| 32: | { |
| 33: | public function renderTab(Representation $r) |
| 34: | { |
| 35: | if (!($r instanceof SourceRepresentation) || empty($r->source)) { |
| 36: | return false; |
| 37: | } |
| 38: | |
| 39: | $source = $r->source; |
| 40: | |
| 41: | |
| 42: | foreach ($source as $linenum => $line) { |
| 43: | if (\strlen(\trim($line)) || $linenum === $r->line) { |
| 44: | break; |
| 45: | } |
| 46: | |
| 47: | unset($source[$linenum]); |
| 48: | } |
| 49: | |
| 50: | foreach (\array_reverse($source, true) as $linenum => $line) { |
| 51: | if (\strlen(\trim($line)) || $linenum === $r->line) { |
| 52: | break; |
| 53: | } |
| 54: | |
| 55: | unset($source[$linenum]); |
| 56: | } |
| 57: | |
| 58: | $output = ''; |
| 59: | |
| 60: | foreach ($source as $linenum => $line) { |
| 61: | if ($linenum === $r->line) { |
| 62: | $output .= '<div class="kint-highlight">'.$this->renderer->escape($line)."\n".'</div>'; |
| 63: | } else { |
| 64: | $output .= '<div>'.$this->renderer->escape($line)."\n".'</div>'; |
| 65: | } |
| 66: | } |
| 67: | |
| 68: | if ($output) { |
| 69: | \reset($source); |
| 70: | |
| 71: | $data = ''; |
| 72: | if ($r->showfilename) { |
| 73: | $data = ' data-kint-filename="'.$this->renderer->escape($r->filename).'"'; |
| 74: | } |
| 75: | |
| 76: | return '<div><pre class="kint-source"'.$data.' style="counter-reset: kint-l '.((int) \key($source) - 1).';">'.$output.'</pre></div><div></div>'; |
| 77: | } |
| 78: | } |
| 79: | } |
| 80: | |