| 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\Kint; |
| 29: | use Kint\Object\Representation\DocstringRepresentation; |
| 30: | use Kint\Object\Representation\Representation; |
| 31: | |
| 32: | class DocstringPlugin extends Plugin implements TabPluginInterface |
| 33: | { |
| 34: | public function renderTab(Representation $r) |
| 35: | { |
| 36: | if (!($r instanceof DocstringRepresentation)) { |
| 37: | return false; |
| 38: | } |
| 39: | |
| 40: | $docstring = array(); |
| 41: | foreach (\explode("\n", $r->contents) as $line) { |
| 42: | $docstring[] = \trim($line); |
| 43: | } |
| 44: | |
| 45: | $docstring = \implode("\n", $docstring); |
| 46: | |
| 47: | $location = array(); |
| 48: | |
| 49: | if ($r->class) { |
| 50: | $location[] = 'Inherited from '.$this->renderer->escape($r->class); |
| 51: | } |
| 52: | if ($r->file && $r->line) { |
| 53: | $location[] = 'Defined in '.$this->renderer->escape(Kint::shortenPath($r->file)).':'.((int) $r->line); |
| 54: | } |
| 55: | |
| 56: | $location = \implode("\n", $location); |
| 57: | |
| 58: | if ($location) { |
| 59: | if (\strlen($docstring)) { |
| 60: | $docstring .= "\n\n"; |
| 61: | } |
| 62: | |
| 63: | $location = '<small>'.$location.'</small>'; |
| 64: | } elseif (0 === \strlen($docstring)) { |
| 65: | return ''; |
| 66: | } |
| 67: | |
| 68: | return '<pre>'.$this->renderer->escape($docstring).$location.'</pre>'; |
| 69: | } |
| 70: | } |
| 71: | |