This commit is contained in:
Markus
2022-04-28 09:40:10 +02:00
commit 795794f992
9586 changed files with 1146991 additions and 0 deletions

View File

@@ -0,0 +1,183 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer;
use Exception;
use Kint\Zval\Value;
use Throwable;
class CliRenderer extends TextRenderer
{
/**
* @var bool enable colors when Kint is run in *UNIX* command line
*/
public static $cli_colors = true;
/**
* Forces utf8 output on windows.
*
* @var bool
*/
public static $force_utf8 = false;
/**
* Detects the terminal width on startup.
*
* @var bool
*/
public static $detect_width = true;
/**
* The minimum width to detect terminal size as.
*
* Less than this is ignored and falls back to default width.
*
* @var int
*/
public static $min_terminal_width = 40;
/**
* Which stream to check for VT100 support on windows.
*
* null uses STDOUT if it's defined
*
* @var null|resource
*/
public static $windows_stream = null;
protected static $terminal_width = null;
protected $windows_output = false;
protected $colors = false;
public function __construct()
{
parent::__construct();
if (!self::$force_utf8 && KINT_WIN) {
if (!KINT_PHP72) {
$this->windows_output = true;
} else {
$stream = self::$windows_stream;
if (!$stream && \defined('STDOUT')) {
$stream = STDOUT;
}
if (!$stream) {
$this->windows_output = true;
} else {
$this->windows_output = !\sapi_windows_vt100_support($stream);
}
}
}
if (!self::$terminal_width) {
if (!KINT_WIN && self::$detect_width) {
try {
self::$terminal_width = \exec('tput cols');
} catch (Exception $e) {
self::$terminal_width = self::$default_width;
} catch (Throwable $t) {
self::$terminal_width = self::$default_width;
}
}
if (self::$terminal_width < self::$min_terminal_width) {
self::$terminal_width = self::$default_width;
}
}
$this->colors = $this->windows_output ? false : self::$cli_colors;
$this->header_width = self::$terminal_width;
}
public function colorValue($string)
{
if (!$this->colors) {
return $string;
}
return "\x1b[32m".\str_replace("\n", "\x1b[0m\n\x1b[32m", $string)."\x1b[0m";
}
public function colorType($string)
{
if (!$this->colors) {
return $string;
}
return "\x1b[35;1m".\str_replace("\n", "\x1b[0m\n\x1b[35;1m", $string)."\x1b[0m";
}
public function colorTitle($string)
{
if (!$this->colors) {
return $string;
}
return "\x1b[36m".\str_replace("\n", "\x1b[0m\n\x1b[36m", $string)."\x1b[0m";
}
public function renderTitle(Value $o)
{
if ($this->windows_output) {
return $this->utf8ToWindows(parent::renderTitle($o));
}
return parent::renderTitle($o);
}
public function preRender()
{
return PHP_EOL;
}
public function postRender()
{
if ($this->windows_output) {
return $this->utf8ToWindows(parent::postRender());
}
return parent::postRender();
}
public function escape($string, $encoding = false)
{
return \str_replace("\x1b", '\\x1b', $string);
}
protected function utf8ToWindows($string)
{
return \str_replace(
['┌', '═', '┐', '│', '└', '─', '┘'],
[' ', '=', ' ', '|', ' ', '-', ' '],
$string
);
}
}

View File

@@ -0,0 +1,237 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer;
use Kint\Kint;
use Kint\Zval\BlobValue;
use Kint\Zval\Value;
class PlainRenderer extends TextRenderer
{
public static $pre_render_sources = [
'script' => [
['Kint\\Renderer\\PlainRenderer', 'renderJs'],
['Kint\\Renderer\\Text\\MicrotimePlugin', 'renderJs'],
],
'style' => [
['Kint\\Renderer\\PlainRenderer', 'renderCss'],
],
'raw' => [],
];
/**
* Path to the CSS file to load by default.
*
* @var string
*/
public static $theme = 'plain.css';
/**
* Output htmlentities instead of utf8.
*
* @var bool
*/
public static $disable_utf8 = false;
public static $needs_pre_render = true;
public static $always_pre_render = false;
protected $force_pre_render = false;
protected $pre_render;
public function __construct()
{
parent::__construct();
$this->pre_render = self::$needs_pre_render;
if (self::$always_pre_render) {
$this->setPreRender(true);
}
}
public function setCallInfo(array $info)
{
parent::setCallInfo($info);
if (\in_array('@', $this->call_info['modifiers'], true)) {
$this->setPreRender(true);
}
}
public function setStatics(array $statics)
{
parent::setStatics($statics);
if (!empty($statics['return'])) {
$this->setPreRender(true);
}
}
public function setPreRender($pre_render)
{
$this->pre_render = $pre_render;
$this->force_pre_render = true;
}
public function getPreRender()
{
return $this->pre_render;
}
public function colorValue($string)
{
return '<i>'.$string.'</i>';
}
public function colorType($string)
{
return '<b>'.$string.'</b>';
}
public function colorTitle($string)
{
return '<u>'.$string.'</u>';
}
public function renderTitle(Value $o)
{
if (self::$disable_utf8) {
return $this->utf8ToHtmlentity(parent::renderTitle($o));
}
return parent::renderTitle($o);
}
public function preRender()
{
$output = '';
if ($this->pre_render) {
foreach (self::$pre_render_sources as $type => $values) {
$contents = '';
foreach ($values as $v) {
$contents .= \call_user_func($v, $this);
}
if (!\strlen($contents)) {
continue;
}
switch ($type) {
case 'script':
$output .= '<script class="kint-plain-script">'.$contents.'</script>';
break;
case 'style':
$output .= '<style class="kint-plain-style">'.$contents.'</style>';
break;
default:
$output .= $contents;
}
}
// Don't pre-render on every dump
if (!$this->force_pre_render) {
self::$needs_pre_render = false;
}
}
return $output.'<div class="kint-plain">';
}
public function postRender()
{
if (self::$disable_utf8) {
return $this->utf8ToHtmlentity(parent::postRender()).'</div>';
}
return parent::postRender().'</div>';
}
public function ideLink($file, $line)
{
$path = $this->escape(Kint::shortenPath($file)).':'.$line;
$ideLink = Kint::getIdeLink($file, $line);
if (!$ideLink) {
return $path;
}
$class = '';
if (\preg_match('/https?:\\/\\//i', $ideLink)) {
$class = 'class="kint-ide-link" ';
}
return '<a '.$class.'href="'.$this->escape($ideLink).'">'.$path.'</a>';
}
public function escape($string, $encoding = false)
{
if (false === $encoding) {
$encoding = BlobValue::detectEncoding($string);
}
$original_encoding = $encoding;
if (false === $encoding || 'ASCII' === $encoding) {
$encoding = 'UTF-8';
}
$string = \htmlspecialchars($string, ENT_NOQUOTES, $encoding);
// this call converts all non-ASCII characters into numeirc htmlentities
if (\function_exists('mb_encode_numericentity') && 'ASCII' !== $original_encoding) {
$string = \mb_encode_numericentity($string, [0x80, 0xFFFF, 0, 0xFFFF], $encoding);
}
return $string;
}
protected function utf8ToHtmlentity($string)
{
return \str_replace(
['┌', '═', '┐', '│', '└', '─', '┘'],
['&#9484;', '&#9552;', '&#9488;', '&#9474;', '&#9492;', '&#9472;', '&#9496;'],
$string
);
}
protected static function renderJs()
{
return \file_get_contents(KINT_DIR.'/resources/compiled/shared.js').\file_get_contents(KINT_DIR.'/resources/compiled/plain.js');
}
protected static function renderCss()
{
if (\file_exists(KINT_DIR.'/resources/compiled/'.self::$theme)) {
return \file_get_contents(KINT_DIR.'/resources/compiled/'.self::$theme);
}
return \file_get_contents(self::$theme);
}
}

View File

@@ -0,0 +1,185 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer;
use Kint\Zval\InstanceValue;
use Kint\Zval\Value;
abstract class Renderer
{
const SORT_NONE = 0;
const SORT_VISIBILITY = 1;
const SORT_FULL = 2;
protected $call_info = [];
protected $statics = [];
protected $show_trace = true;
abstract public function render(Value $o);
abstract public function renderNothing();
public function setCallInfo(array $info)
{
if (!isset($info['params'])) {
$info['params'] = null;
}
if (!isset($info['modifiers']) || !\is_array($info['modifiers'])) {
$info['modifiers'] = [];
}
if (!isset($info['callee'])) {
$info['callee'] = null;
}
if (!isset($info['caller'])) {
$info['caller'] = null;
}
if (!isset($info['trace']) || !\is_array($info['trace'])) {
$info['trace'] = [];
}
$this->call_info = [
'params' => $info['params'],
'modifiers' => $info['modifiers'],
'callee' => $info['callee'],
'caller' => $info['caller'],
'trace' => $info['trace'],
];
}
public function getCallInfo()
{
return $this->call_info;
}
public function setStatics(array $statics)
{
$this->statics = $statics;
$this->setShowTrace(!empty($statics['display_called_from']));
}
public function getStatics()
{
return $this->statics;
}
public function setShowTrace($show_trace)
{
$this->show_trace = $show_trace;
}
public function getShowTrace()
{
return $this->show_trace;
}
/**
* Returns the first compatible plugin available.
*
* @param array $plugins Array of hints to class strings
* @param array $hints Array of object hints
*
* @return array Array of hints to class strings filtered and sorted by object hints
*/
public function matchPlugins(array $plugins, array $hints)
{
$out = [];
foreach ($hints as $key) {
if (isset($plugins[$key])) {
$out[$key] = $plugins[$key];
}
}
return $out;
}
public function filterParserPlugins(array $plugins)
{
return $plugins;
}
public function preRender()
{
return '';
}
public function postRender()
{
return '';
}
public static function sortPropertiesFull(Value $a, Value $b)
{
$sort = Value::sortByAccess($a, $b);
if ($sort) {
return $sort;
}
$sort = Value::sortByName($a, $b);
if ($sort) {
return $sort;
}
return InstanceValue::sortByHierarchy($a->owner_class, $b->owner_class);
}
/**
* Sorts an array of Value.
*
* @param Value[] $contents Object properties to sort
* @param int $sort
*
* @return Value[]
*/
public static function sortProperties(array $contents, $sort)
{
switch ($sort) {
case self::SORT_VISIBILITY:
// Containers to quickly stable sort by type
$containers = [
Value::ACCESS_PUBLIC => [],
Value::ACCESS_PROTECTED => [],
Value::ACCESS_PRIVATE => [],
Value::ACCESS_NONE => [],
];
foreach ($contents as $item) {
$containers[$item->access][] = $item;
}
return \call_user_func_array('array_merge', $containers);
case self::SORT_FULL:
\usort($contents, ['Kint\\Renderer\\Renderer', 'sortPropertiesFull']);
// no break
default:
return $contents;
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\Value;
class ArrayLimitPlugin extends Plugin implements ValuePluginInterface
{
public function renderValue(Value $o)
{
return '<dl>'.$this->renderLockedHeader($o, '<var>Array Limit</var>').'</dl>';
}
}

View File

@@ -0,0 +1,56 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\Representation\Representation;
class BinaryPlugin extends Plugin implements TabPluginInterface
{
public static $line_length = 0x10;
public static $chunk_length = 0x4;
public function renderTab(Representation $r)
{
$out = '<pre>';
/** @var string[] Psalm bug workaround */
$lines = \str_split($r->contents, self::$line_length);
foreach ($lines as $index => $line) {
$out .= \sprintf('%08X', $index * self::$line_length).":\t";
/** @var string[] Psalm bug workaround */
$chunks = \str_split(\str_pad(\bin2hex($line), 2 * self::$line_length, ' '), self::$chunk_length);
$out .= \implode(' ', $chunks);
$out .= "\t".\preg_replace('/[^\\x20-\\x7E]/', '.', $line)."\n";
}
$out .= '</pre>';
return $out;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\Value;
class BlacklistPlugin extends Plugin implements ValuePluginInterface
{
public function renderValue(Value $o)
{
return '<dl>'.$this->renderLockedHeader($o, '<var>Blacklisted</var>').'</dl>';
}
}

View File

@@ -0,0 +1,174 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Renderer\RichRenderer;
use Kint\Utils;
use Kint\Zval\ClosureValue;
use Kint\Zval\MethodValue;
use Kint\Zval\Value;
class CallablePlugin extends Plugin implements ValuePluginInterface
{
protected static $method_cache = [];
public function renderValue(Value $o)
{
if ($o instanceof MethodValue) {
return $this->renderMethod($o);
}
if ($o instanceof ClosureValue) {
return $this->renderClosure($o);
}
return $this->renderCallable($o);
}
protected function renderClosure(ClosureValue $o)
{
$children = $this->renderer->renderChildren($o);
$header = '';
if (null !== ($s = $o->getModifiers())) {
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getName())) {
$header .= '<dfn>'.$this->renderer->escape($s).'('.$this->renderer->escape($o->getParams()).')</dfn>';
}
if (null !== ($s = $o->getValueShort())) {
if (RichRenderer::$strlen_max) {
$s = Utils::truncateString($s, RichRenderer::$strlen_max);
}
$header .= ' '.$this->renderer->escape($s);
}
return '<dl>'.$this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header).$children.'</dl>';
}
protected function renderCallable(Value $o)
{
$children = $this->renderer->renderChildren($o);
$header = '';
if (null !== ($s = $o->getModifiers())) {
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getName())) {
$header .= '<dfn>'.$this->renderer->escape($s).'</dfn>';
}
if (null !== ($s = $o->getValueShort())) {
if (RichRenderer::$strlen_max) {
$s = Utils::truncateString($s, RichRenderer::$strlen_max);
}
$header .= ' '.$this->renderer->escape($s);
}
return '<dl>'.$this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header).$children.'</dl>';
}
protected function renderMethod(MethodValue $o)
{
if (!empty(self::$method_cache[$o->owner_class][$o->name])) {
$children = self::$method_cache[$o->owner_class][$o->name]['children'];
$header = $this->renderer->renderHeaderWrapper(
$o,
(bool) \strlen($children),
self::$method_cache[$o->owner_class][$o->name]['header']
);
return '<dl>'.$header.$children.'</dl>';
}
$children = $this->renderer->renderChildren($o);
$header = '';
if (null !== ($s = $o->getModifiers()) || $o->return_reference) {
$header .= '<var>'.$s;
if ($o->return_reference) {
if ($s) {
$header .= ' ';
}
$header .= $this->renderer->escape('&');
}
$header .= '</var> ';
}
if (null !== ($s = $o->getName())) {
$function = $this->renderer->escape($s).'('.$this->renderer->escape($o->getParams()).')';
if (null !== ($url = $o->getPhpDocUrl())) {
$function = '<a href="'.$url.'" target=_blank>'.$function.'</a>';
}
$header .= '<dfn>'.$function.'</dfn>';
}
if (!empty($o->returntype)) {
$header .= ': <var>';
if ($o->return_reference) {
$header .= $this->renderer->escape('&');
}
$header .= $this->renderer->escape($o->returntype).'</var>';
} elseif ($o->docstring) {
if (\preg_match('/@return\\s+(.*)\\r?\\n/m', $o->docstring, $matches)) {
if (\trim($matches[1])) {
$header .= ': <var>'.$this->renderer->escape(\trim($matches[1])).'</var>';
}
}
}
if (null !== ($s = $o->getValueShort())) {
if (RichRenderer::$strlen_max) {
$s = Utils::truncateString($s, RichRenderer::$strlen_max);
}
$header .= ' '.$this->renderer->escape($s);
}
if (\strlen($o->owner_class) && \strlen($o->name)) {
self::$method_cache[$o->owner_class][$o->name] = [
'header' => $header,
'children' => $children,
];
}
$header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header);
return '<dl>'.$header.$children.'</dl>';
}
}

View File

@@ -0,0 +1,59 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Kint;
use Kint\Zval\ClosureValue;
use Kint\Zval\Value;
class ClosurePlugin extends Plugin implements ValuePluginInterface
{
public function renderValue(Value $o)
{
$children = $this->renderer->renderChildren($o);
if (!($o instanceof ClosureValue)) {
$header = $this->renderer->renderHeader($o);
} else {
$header = '';
if (null !== ($s = $o->getModifiers())) {
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getName())) {
$header .= '<dfn>'.$this->renderer->escape($s).'('.$this->renderer->escape($o->getParams()).')</dfn> ';
}
$header .= '<var>Closure</var> ';
$header .= $this->renderer->escape(Kint::shortenPath($o->filename)).':'.(int) $o->startline;
}
$header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header);
return '<dl>'.$header.$children.'</dl>';
}
}

View File

@@ -0,0 +1,100 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\Representation\ColorRepresentation;
use Kint\Zval\Representation\Representation;
use Kint\Zval\Value;
class ColorPlugin extends Plugin implements TabPluginInterface, ValuePluginInterface
{
public function renderValue(Value $o)
{
$r = $o->getRepresentation('color');
if (!$r instanceof ColorRepresentation) {
return;
}
$children = $this->renderer->renderChildren($o);
$header = $this->renderer->renderHeader($o);
$header .= '<div class="kint-color-preview"><div style="background:';
$header .= $r->getColor(ColorRepresentation::COLOR_RGBA);
$header .= '"></div></div>';
$header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header);
return '<dl>'.$header.$children.'</dl>';
}
public function renderTab(Representation $r)
{
if (!$r instanceof ColorRepresentation) {
return;
}
$out = '';
if ($color = $r->getColor(ColorRepresentation::COLOR_NAME)) {
$out .= '<dfn>'.$color."</dfn>\n";
}
if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_3)) {
$out .= '<dfn>'.$color."</dfn>\n";
}
if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_6)) {
$out .= '<dfn>'.$color."</dfn>\n";
}
if ($r->hasAlpha()) {
if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_4)) {
$out .= '<dfn>'.$color."</dfn>\n";
}
if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_8)) {
$out .= '<dfn>'.$color."</dfn>\n";
}
if ($color = $r->getColor(ColorRepresentation::COLOR_RGBA)) {
$out .= '<dfn>'.$color."</dfn>\n";
}
if ($color = $r->getColor(ColorRepresentation::COLOR_HSLA)) {
$out .= '<dfn>'.$color."</dfn>\n";
}
} else {
if ($color = $r->getColor(ColorRepresentation::COLOR_RGB)) {
$out .= '<dfn>'.$color."</dfn>\n";
}
if ($color = $r->getColor(ColorRepresentation::COLOR_HSL)) {
$out .= '<dfn>'.$color."</dfn>\n";
}
}
if (!\strlen($out)) {
return;
}
return '<pre>'.$out.'</pre>';
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\Value;
class DepthLimitPlugin extends Plugin implements ValuePluginInterface
{
public function renderValue(Value $o)
{
return '<dl>'.$this->renderLockedHeader($o, '<var>Depth Limit</var>').'</dl>';
}
}

View File

@@ -0,0 +1,70 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Kint;
use Kint\Zval\Representation\DocstringRepresentation;
use Kint\Zval\Representation\Representation;
class DocstringPlugin extends Plugin implements TabPluginInterface
{
public function renderTab(Representation $r)
{
if (!($r instanceof DocstringRepresentation)) {
return;
}
$docstring = [];
foreach (\explode("\n", $r->contents) as $line) {
$docstring[] = \trim($line);
}
$docstring = \implode("\n", $docstring);
$location = [];
if ($r->class) {
$location[] = 'Inherited from '.$this->renderer->escape($r->class);
}
if ($r->file && $r->line) {
$location[] = 'Defined in '.$this->renderer->escape(Kint::shortenPath($r->file)).':'.((int) $r->line);
}
$location = \implode("\n", $location);
if ($location) {
if (\strlen($docstring)) {
$docstring .= "\n\n";
}
$location = '<small>'.$location.'</small>';
} elseif (0 === \strlen($docstring)) {
return '';
}
return '<pre>'.$this->renderer->escape($docstring).$location.'</pre>';
}
}

View File

@@ -0,0 +1,68 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Utils;
use Kint\Zval\Representation\MicrotimeRepresentation;
use Kint\Zval\Representation\Representation;
class MicrotimePlugin extends Plugin implements TabPluginInterface
{
public function renderTab(Representation $r)
{
if (!($r instanceof MicrotimeRepresentation)) {
return;
}
$out = $r->getDateTime()->format('Y-m-d H:i:s.u');
if (null !== $r->lap) {
$out .= '<br><b>SINCE LAST CALL:</b> <span class="kint-microtime-lap">'.\round($r->lap, 4).'</span>s.';
}
if (null !== $r->total) {
$out .= '<br><b>SINCE START:</b> '.\round($r->total, 4).'s.';
}
if (null !== $r->avg) {
$out .= '<br><b>AVERAGE DURATION:</b> <span class="kint-microtime-avg">'.\round($r->avg, 4).'</span>s.';
}
$bytes = Utils::getHumanReadableBytes($r->mem);
$out .= '<br><b>MEMORY USAGE:</b> '.$r->mem.' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
$bytes = Utils::getHumanReadableBytes($r->mem_real);
$out .= ' (real '.\round($bytes['value'], 3).' '.$bytes['unit'].')';
$bytes = Utils::getHumanReadableBytes($r->mem_peak);
$out .= '<br><b>PEAK MEMORY USAGE:</b> '.$r->mem_peak.' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
$bytes = Utils::getHumanReadableBytes($r->mem_peak_real);
$out .= ' (real '.\round($bytes['value'], 3).' '.$bytes['unit'].')';
return '<pre data-kint-microtime-group="'.$r->group.'">'.$out.'</pre>';
}
public static function renderJs()
{
return \file_get_contents(KINT_DIR.'/resources/compiled/microtime.js');
}
}

View File

@@ -0,0 +1,89 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Renderer\RichRenderer;
use Kint\Zval\Value;
abstract class Plugin implements PluginInterface
{
protected $renderer;
public function __construct(RichRenderer $r)
{
$this->renderer = $r;
}
/**
* Renders a locked header.
*
* @param string $content
*/
public function renderLockedHeader(Value $o, $content)
{
$header = '<dt class="kint-parent kint-locked">';
if (RichRenderer::$access_paths && $o->depth > 0 && $ap = $o->getAccessPath()) {
$header .= '<span class="kint-access-path-trigger" title="Show access path">&rlarr;</span>';
}
$header .= '<span class="kint-popup-trigger" title="Open in new window">&boxbox;</span><nav></nav>';
if (null !== ($s = $o->getModifiers())) {
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getName())) {
$header .= '<dfn>'.$this->renderer->escape($s).'</dfn> ';
if ($s = $o->getOperator()) {
$header .= $this->renderer->escape($s, 'ASCII').' ';
}
}
if (null !== ($s = $o->getType())) {
$s = $this->renderer->escape($s);
if ($o->reference) {
$s = '&amp;'.$s;
}
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getSize())) {
$header .= '('.$this->renderer->escape($s).') ';
}
$header .= $content;
if (!empty($ap)) {
$header .= '<div class="access-path">'.$this->renderer->escape($ap).'</div>';
}
return $header.'</dt>';
}
}

View File

@@ -0,0 +1,33 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Renderer\RichRenderer;
interface PluginInterface
{
public function __construct(RichRenderer $r);
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\Value;
class RecursionPlugin extends Plugin implements ValuePluginInterface
{
public function renderValue(Value $o)
{
return '<dl>'.$this->renderLockedHeader($o, '<var>Recursion</var>').'</dl>';
}
}

View File

@@ -0,0 +1,77 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Renderer\RichRenderer;
use Kint\Utils;
use Kint\Zval\Value;
class SimpleXMLElementPlugin extends Plugin implements ValuePluginInterface
{
public function renderValue(Value $o)
{
$children = $this->renderer->renderChildren($o);
$header = '';
if (null !== ($s = $o->getModifiers())) {
$header .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getName())) {
$header .= '<dfn>'.$this->renderer->escape($s).'</dfn> ';
if ($s = $o->getOperator()) {
$header .= $this->renderer->escape($s, 'ASCII').' ';
}
}
if (null !== ($s = $o->getType())) {
$s = $this->renderer->escape($s);
if ($o->reference) {
$s = '&amp;'.$s;
}
$header .= '<var>'.$this->renderer->escape($s).'</var> ';
}
if (null !== ($s = $o->getSize())) {
$header .= '('.$this->renderer->escape($s).') ';
}
if (null !== ($s = $o->getValueShort())) {
if (RichRenderer::$strlen_max) {
$s = Utils::truncateString($s, RichRenderer::$strlen_max);
}
$header .= $this->renderer->escape($s);
}
$header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header);
return '<dl>'.$header.$children.'</dl>';
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\Representation\Representation;
use Kint\Zval\Representation\SourceRepresentation;
class SourcePlugin extends Plugin implements TabPluginInterface
{
public function renderTab(Representation $r)
{
if (!($r instanceof SourceRepresentation) || empty($r->source)) {
return;
}
$source = $r->source;
// Trim empty lines from the start and end of the source
foreach ($source as $linenum => $line) {
if (\strlen(\trim($line)) || $linenum === $r->line) {
break;
}
unset($source[$linenum]);
}
foreach (\array_reverse($source, true) as $linenum => $line) {
if (\strlen(\trim($line)) || $linenum === $r->line) {
break;
}
unset($source[$linenum]);
}
$output = '';
foreach ($source as $linenum => $line) {
if ($linenum === $r->line) {
$output .= '<div class="kint-highlight">'.$this->renderer->escape($line)."\n".'</div>';
} else {
$output .= '<div>'.$this->renderer->escape($line)."\n".'</div>';
}
}
if ($output) {
\reset($source);
$data = '';
if ($r->showfilename) {
$data = ' data-kint-filename="'.$this->renderer->escape($r->filename).'"';
}
return '<div><pre class="kint-source"'.$data.' style="counter-reset: kint-l '.((int) \key($source) - 1).';">'.$output.'</pre></div><div></div>';
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\Representation\Representation;
interface TabPluginInterface extends PluginInterface
{
/**
* @return null|string
*/
public function renderTab(Representation $r);
}

View File

@@ -0,0 +1,133 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Renderer\RichRenderer;
use Kint\Utils;
use Kint\Zval\Representation\Representation;
class TablePlugin extends Plugin implements TabPluginInterface
{
public static $respect_str_length = true;
public function renderTab(Representation $r)
{
$out = '<pre><table><thead><tr><th></th>';
$firstrow = \reset($r->contents);
foreach ($firstrow->value->contents as $field) {
$out .= '<th>'.$this->renderer->escape($field->name).'</th>';
}
$out .= '</tr></thead><tbody>';
foreach ($r->contents as $row) {
$out .= '<tr><th>';
$out .= $this->renderer->escape($row->name);
$out .= '</th>';
foreach ($row->value->contents as $field) {
$out .= '<td';
$type = '';
$size = '';
$ref = '';
if (null !== ($s = $field->getType())) {
$type = $this->renderer->escape($s);
if ($field->reference) {
$ref = '&amp;';
$type = $ref.$type;
}
if (null !== ($s = $field->getSize())) {
$size .= ' ('.$this->renderer->escape($s).')';
}
}
if ($type) {
$out .= ' title="'.$type.$size.'"';
}
$out .= '>';
switch ($field->type) {
case 'boolean':
$out .= $field->value->contents ? '<var>'.$ref.'true</var>' : '<var>'.$ref.'false</var>';
break;
case 'integer':
case 'double':
$out .= (string) $field->value->contents;
break;
case 'null':
$out .= '<var>'.$ref.'null</var>';
break;
case 'string':
if ($field->encoding) {
$val = $field->value->contents;
if (RichRenderer::$strlen_max && self::$respect_str_length) {
$val = Utils::truncateString($val, RichRenderer::$strlen_max);
}
$out .= $this->renderer->escape($val);
} else {
$out .= '<var>'.$type.'</var>';
}
break;
case 'array':
$out .= '<var>'.$ref.'array</var>'.$size;
break;
case 'object':
$out .= '<var>'.$ref.$this->renderer->escape($field->classname).'</var>'.$size;
break;
case 'resource':
$out .= '<var>'.$ref.'resource</var>';
break;
default:
$out .= '<var>'.$ref.'unknown</var>';
break;
}
if (\in_array('blacklist', $field->hints, true)) {
$out .= ' <var>Blacklisted</var>';
} elseif (\in_array('recursion', $field->hints, true)) {
$out .= ' <var>Recursion</var>';
} elseif (\in_array('depth_limit', $field->hints, true)) {
$out .= ' <var>Depth Limit</var>';
}
$out .= '</td>';
}
$out .= '</tr>';
}
$out .= '</tbody></table></pre>';
return $out;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use DateTime;
use DateTimeZone;
use Kint\Zval\Representation\Representation;
class TimestampPlugin extends Plugin implements TabPluginInterface
{
public function renderTab(Representation $r)
{
$dt = DateTime::createFromFormat('U', $r->contents);
if ($dt) {
return '<pre>'.$dt->setTimeZone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s T').'</pre>';
}
}
}

View File

@@ -0,0 +1,68 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\TraceFrameValue;
use Kint\Zval\Value;
class TraceFramePlugin extends Plugin implements ValuePluginInterface
{
public function renderValue(Value $o)
{
if (!$o instanceof TraceFrameValue) {
return;
}
if (!empty($o->trace['file']) && !empty($o->trace['line'])) {
$header = '<var>'.$this->renderer->ideLink($o->trace['file'], (int) $o->trace['line']).'</var> ';
} else {
$header = '<var>PHP internal call</var> ';
}
if ($o->trace['class']) {
$header .= $this->renderer->escape($o->trace['class'].$o->trace['type']);
}
if (\is_string($o->trace['function'])) {
$function = $this->renderer->escape($o->trace['function'].'()');
} else {
$function = $this->renderer->escape(
$o->trace['function']->getName().'('.$o->trace['function']->getParams().')'
);
if (null !== ($url = $o->trace['function']->getPhpDocUrl())) {
$function = '<a href="'.$url.'" target=_blank>'.$function.'</a>';
}
}
$header .= '<dfn>'.$function.'</dfn>';
$children = $this->renderer->renderChildren($o);
$header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header);
return '<dl>'.$header.$children.'</dl>';
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Rich;
use Kint\Zval\Value;
interface ValuePluginInterface extends PluginInterface
{
/**
* @return null|string
*/
public function renderValue(Value $o);
}

View File

@@ -0,0 +1,633 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer;
use Kint\Kint;
use Kint\Utils;
use Kint\Zval\BlobValue;
use Kint\Zval\InstanceValue;
use Kint\Zval\Representation\Representation;
use Kint\Zval\Value;
class RichRenderer extends Renderer
{
/**
* RichRenderer value plugins should implement Kint\Renderer\Rich\ValuePluginInterface.
*/
public static $value_plugins = [
'array_limit' => 'Kint\\Renderer\\Rich\\ArrayLimitPlugin',
'blacklist' => 'Kint\\Renderer\\Rich\\BlacklistPlugin',
'callable' => 'Kint\\Renderer\\Rich\\CallablePlugin',
'closure' => 'Kint\\Renderer\\Rich\\ClosurePlugin',
'color' => 'Kint\\Renderer\\Rich\\ColorPlugin',
'depth_limit' => 'Kint\\Renderer\\Rich\\DepthLimitPlugin',
'recursion' => 'Kint\\Renderer\\Rich\\RecursionPlugin',
'simplexml_element' => 'Kint\\Renderer\\Rich\\SimpleXMLElementPlugin',
'trace_frame' => 'Kint\\Renderer\\Rich\\TraceFramePlugin',
];
/**
* RichRenderer tab plugins should implement Kint\Renderer\Rich\TabPluginInterface.
*/
public static $tab_plugins = [
'binary' => 'Kint\\Renderer\\Rich\\BinaryPlugin',
'color' => 'Kint\\Renderer\\Rich\\ColorPlugin',
'docstring' => 'Kint\\Renderer\\Rich\\DocstringPlugin',
'microtime' => 'Kint\\Renderer\\Rich\\MicrotimePlugin',
'source' => 'Kint\\Renderer\\Rich\\SourcePlugin',
'table' => 'Kint\\Renderer\\Rich\\TablePlugin',
'timestamp' => 'Kint\\Renderer\\Rich\\TimestampPlugin',
];
public static $pre_render_sources = [
'script' => [
['Kint\\Renderer\\RichRenderer', 'renderJs'],
['Kint\\Renderer\\Rich\\MicrotimePlugin', 'renderJs'],
],
'style' => [
['Kint\\Renderer\\RichRenderer', 'renderCss'],
],
'raw' => [],
];
/**
* Whether or not to render access paths.
*
* Access paths can become incredibly heavy with very deep and wide
* structures. Given mostly public variables it will typically make
* up one quarter of the output HTML size.
*
* If this is an unacceptably large amount and your browser is groaning
* under the weight of the access paths - your first order of buisiness
* should be to get a new browser. Failing that, use this to turn them off.
*
* @var bool
*/
public static $access_paths = true;
/**
* The maximum length of a string before it is truncated.
*
* Falsey to disable
*
* @var int
*/
public static $strlen_max = 80;
/**
* Path to the CSS file to load by default.
*
* @var string
*/
public static $theme = 'original.css';
/**
* Assume types and sizes don't need to be escaped.
*
* Turn this off if you use anything but ascii in your class names,
* but it'll cause a slowdown of around 10%
*
* @var bool
*/
public static $escape_types = false;
/**
* Move all dumps to a folder at the bottom of the body.
*
* @var bool
*/
public static $folder = false;
/**
* Sort mode for object properties.
*
* @var int
*/
public static $sort = self::SORT_NONE;
public static $needs_pre_render = true;
public static $needs_folder_render = true;
public static $always_pre_render = false;
public static $js_nonce = null;
public static $css_nonce = null;
protected $plugin_objs = [];
protected $expand = false;
protected $force_pre_render = false;
protected $pre_render;
protected $use_folder;
public function __construct()
{
$this->pre_render = self::$needs_pre_render;
$this->use_folder = self::$folder;
if (self::$always_pre_render) {
$this->setForcePreRender();
}
}
public function setCallInfo(array $info)
{
parent::setCallInfo($info);
if (\in_array('!', $this->call_info['modifiers'], true)) {
$this->setExpand(true);
$this->use_folder = false;
}
if (\in_array('@', $this->call_info['modifiers'], true)) {
$this->setForcePreRender();
}
}
public function setStatics(array $statics)
{
parent::setStatics($statics);
if (!empty($statics['expanded'])) {
$this->setExpand(true);
}
if (!empty($statics['return'])) {
$this->setForcePreRender();
}
}
public function setExpand($expand)
{
$this->expand = $expand;
}
public function getExpand()
{
return $this->expand;
}
public function setForcePreRender()
{
$this->force_pre_render = true;
$this->pre_render = true;
}
public function setPreRender($pre_render)
{
$this->pre_render = $pre_render;
}
public function getPreRender()
{
return $this->pre_render;
}
public function setUseFolder($use_folder)
{
$this->use_folder = $use_folder;
}
public function getUseFolder()
{
return $this->use_folder;
}
public function render(Value $o)
{
if ($plugin = $this->getPlugin(self::$value_plugins, $o->hints)) {
$output = $plugin->renderValue($o);
if (null !== $output && \strlen($output)) {
return $output;
}
}
$children = $this->renderChildren($o);
$header = $this->renderHeaderWrapper($o, (bool) \strlen($children), $this->renderHeader($o));
return '<dl>'.$header.$children.'</dl>';
}
public function renderNothing()
{
return '<dl><dt><var>No argument</var></dt></dl>';
}
public function renderHeaderWrapper(Value $o, $has_children, $contents)
{
$out = '<dt';
if ($has_children) {
$out .= ' class="kint-parent';
if ($this->expand) {
$out .= ' kint-show';
}
$out .= '"';
}
$out .= '>';
if (self::$access_paths && $o->depth > 0 && $ap = $o->getAccessPath()) {
$out .= '<span class="kint-access-path-trigger" title="Show access path">&rlarr;</span>';
}
if ($has_children) {
$out .= '<span class="kint-popup-trigger" title="Open in new window">&boxbox;</span>';
if (0 === $o->depth) {
$out .= '<span class="kint-search-trigger" title="Show search box">&telrec;</span>';
$out .= '<input type="text" class="kint-search" value="">';
}
$out .= '<nav></nav>';
}
$out .= $contents;
if (!empty($ap)) {
$out .= '<div class="access-path">'.$this->escape($ap).'</div>';
}
return $out.'</dt>';
}
public function renderHeader(Value $o)
{
$output = '';
if (null !== ($s = $o->getModifiers())) {
$output .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getName())) {
$output .= '<dfn>'.$this->escape($s).'</dfn> ';
if ($s = $o->getOperator()) {
$output .= $this->escape($s, 'ASCII').' ';
}
}
if (null !== ($s = $o->getType())) {
if (self::$escape_types) {
$s = $this->escape($s);
}
if ($o->reference) {
$s = '&amp;'.$s;
}
$output .= '<var>'.$s.'</var> ';
}
if (null !== ($s = $o->getSize())) {
if (self::$escape_types) {
$s = $this->escape($s);
}
$output .= '('.$s.') ';
}
if (null !== ($s = $o->getValueShort())) {
$s = \preg_replace('/\\s+/', ' ', $s);
if (self::$strlen_max) {
$s = Utils::truncateString($s, self::$strlen_max);
}
$output .= $this->escape($s);
}
return \trim($output);
}
public function renderChildren(Value $o)
{
$contents = [];
$tabs = [];
foreach ($o->getRepresentations() as $rep) {
$result = $this->renderTab($o, $rep);
if (\strlen($result)) {
$contents[] = $result;
$tabs[] = $rep;
}
}
if (empty($tabs)) {
return '';
}
$output = '<dd>';
if (1 === \count($tabs) && $tabs[0]->labelIsImplicit()) {
$output .= \reset($contents);
} else {
$output .= '<ul class="kint-tabs">';
foreach ($tabs as $i => $tab) {
if (0 === $i) {
$output .= '<li class="kint-active-tab">';
} else {
$output .= '<li>';
}
$output .= $this->escape($tab->getLabel()).'</li>';
}
$output .= '</ul><ul class="kint-tab-contents">';
foreach ($contents as $i => $tab) {
if (0 === $i) {
$output .= '<li class="kint-show">';
} else {
$output .= '<li>';
}
$output .= $tab.'</li>';
}
$output .= '</ul>';
}
return $output.'</dd>';
}
public function preRender()
{
$output = '';
if ($this->pre_render) {
foreach (self::$pre_render_sources as $type => $values) {
$contents = '';
foreach ($values as $v) {
$contents .= \call_user_func($v, $this);
}
if (!\strlen($contents)) {
continue;
}
switch ($type) {
case 'script':
$output .= '<script class="kint-rich-script"';
if (null !== self::$js_nonce) {
$output .= ' nonce="'.\htmlspecialchars(self::$js_nonce).'"';
}
$output .= '>'.$contents.'</script>';
break;
case 'style':
$output .= '<style class="kint-rich-style"';
if (null !== self::$css_nonce) {
$output .= ' nonce="'.\htmlspecialchars(self::$css_nonce).'"';
}
$output .= '>'.$contents.'</style>';
break;
default:
$output .= $contents;
}
}
// Don't pre-render on every dump
if (!$this->force_pre_render) {
self::$needs_pre_render = false;
}
}
$output .= '<div class="kint-rich';
if ($this->use_folder) {
$output .= ' kint-file';
if (self::$needs_folder_render || $this->force_pre_render) {
$output = $this->renderFolder().$output;
if (!$this->force_pre_render) {
self::$needs_folder_render = false;
}
}
}
$output .= '">';
return $output;
}
public function postRender()
{
if (!$this->show_trace) {
return '</div>';
}
$output = '<footer>';
$output .= '<span class="kint-popup-trigger" title="Open in new window">&boxbox;</span> ';
if (!empty($this->call_info['trace']) && \count($this->call_info['trace']) > 1) {
$output .= '<nav></nav>';
}
if (isset($this->call_info['callee']['file'])) {
$output .= 'Called from '.$this->ideLink(
$this->call_info['callee']['file'],
$this->call_info['callee']['line']
);
}
if (isset($this->call_info['callee']['function']) && (
!empty($this->call_info['callee']['class']) ||
!\in_array(
$this->call_info['callee']['function'],
['include', 'include_once', 'require', 'require_once'],
true
)
)
) {
$output .= ' [';
if (isset($this->call_info['callee']['class'])) {
$output .= $this->call_info['callee']['class'];
}
if (isset($this->call_info['callee']['type'])) {
$output .= $this->call_info['callee']['type'];
}
$output .= $this->call_info['callee']['function'].'()]';
}
if (!empty($this->call_info['trace']) && \count($this->call_info['trace']) > 1) {
$output .= '<ol>';
foreach ($this->call_info['trace'] as $index => $step) {
if (!$index) {
continue;
}
$output .= '<li>'.$this->ideLink($step['file'], $step['line']); // closing tag not required
if (isset($step['function'])
&& !\in_array($step['function'], ['include', 'include_once', 'require', 'require_once'], true)
) {
$output .= ' [';
if (isset($step['class'])) {
$output .= $step['class'];
}
if (isset($step['type'])) {
$output .= $step['type'];
}
$output .= $step['function'].'()]';
}
}
$output .= '</ol>';
}
$output .= '</footer></div>';
return $output;
}
public function escape($string, $encoding = false)
{
if (false === $encoding) {
$encoding = BlobValue::detectEncoding($string);
}
$original_encoding = $encoding;
if (false === $encoding || 'ASCII' === $encoding) {
$encoding = 'UTF-8';
}
$string = \htmlspecialchars($string, ENT_NOQUOTES, $encoding);
// this call converts all non-ASCII characters into numeirc htmlentities
if (\function_exists('mb_encode_numericentity') && 'ASCII' !== $original_encoding) {
$string = \mb_encode_numericentity($string, [0x80, 0xFFFF, 0, 0xFFFF], $encoding);
}
return $string;
}
public function ideLink($file, $line)
{
$path = $this->escape(Kint::shortenPath($file)).':'.$line;
$ideLink = Kint::getIdeLink($file, $line);
if (!$ideLink) {
return $path;
}
$class = '';
if (\preg_match('/https?:\\/\\//i', $ideLink)) {
$class = 'class="kint-ide-link" ';
}
return '<a '.$class.'href="'.$this->escape($ideLink).'">'.$path.'</a>';
}
protected function renderTab(Value $o, Representation $rep)
{
if ($plugin = $this->getPlugin(self::$tab_plugins, $rep->hints)) {
$output = $plugin->renderTab($rep);
if (null !== $output && \strlen($output)) {
return $output;
}
}
if (\is_array($rep->contents)) {
$output = '';
if ($o instanceof InstanceValue && 'properties' === $rep->getName()) {
foreach (self::sortProperties($rep->contents, self::$sort) as $obj) {
$output .= $this->render($obj);
}
} else {
foreach ($rep->contents as $obj) {
$output .= $this->render($obj);
}
}
return $output;
}
if (\is_string($rep->contents)) {
$show_contents = false;
// If it is the value representation of a string and its whitespace
// was truncated in the header, always display the full string
if ('string' !== $o->type || $o->value !== $rep) {
$show_contents = true;
} else {
if (\preg_match('/(:?[\\r\\n\\t\\f\\v]| {2})/', $rep->contents)) {
$show_contents = true;
} elseif (self::$strlen_max && null !== $o->getValueShort() && BlobValue::strlen($o->getValueShort()) > self::$strlen_max) {
$show_contents = true;
}
if (empty($o->encoding)) {
$show_contents = false;
}
}
if ($show_contents) {
return '<pre>'.$this->escape($rep->contents)."\n</pre>";
}
}
if ($rep->contents instanceof Value) {
return $this->render($rep->contents);
}
return '';
}
protected function getPlugin(array $plugins, array $hints)
{
if ($plugins = $this->matchPlugins($plugins, $hints)) {
$plugin = \end($plugins);
if (!isset($this->plugin_objs[$plugin])) {
$this->plugin_objs[$plugin] = new $plugin($this);
}
return $this->plugin_objs[$plugin];
}
}
protected static function renderJs()
{
return \file_get_contents(KINT_DIR.'/resources/compiled/shared.js').\file_get_contents(KINT_DIR.'/resources/compiled/rich.js');
}
protected static function renderCss()
{
if (\file_exists(KINT_DIR.'/resources/compiled/'.self::$theme)) {
return \file_get_contents(KINT_DIR.'/resources/compiled/'.self::$theme);
}
return \file_get_contents(self::$theme);
}
protected static function renderFolder()
{
return '<div class="kint-rich kint-folder"><dl><dt class="kint-parent"><nav></nav>Kint</dt><dd class="kint-foldout"></dd></dl></div>';
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Text;
use Kint\Zval\Value;
class ArrayLimitPlugin extends Plugin
{
public function render(Value $o)
{
$out = '';
if (0 == $o->depth) {
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL;
}
$out .= $this->renderer->renderHeader($o).' '.$this->renderer->colorValue('ARRAY LIMIT').PHP_EOL;
return $out;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Text;
use Kint\Zval\Value;
class BlacklistPlugin extends Plugin
{
public function render(Value $o)
{
$out = '';
if (0 == $o->depth) {
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL;
}
$out .= $this->renderer->renderHeader($o).' '.$this->renderer->colorValue('BLACKLISTED').PHP_EOL;
return $out;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Text;
use Kint\Zval\Value;
class DepthLimitPlugin extends Plugin
{
public function render(Value $o)
{
$out = '';
if (0 == $o->depth) {
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL;
}
$out .= $this->renderer->renderHeader($o).' '.$this->renderer->colorValue('DEPTH LIMIT').PHP_EOL;
return $out;
}
}

View File

@@ -0,0 +1,128 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Text;
use Kint\Renderer\PlainRenderer;
use Kint\Renderer\Rich\MicrotimePlugin as RichPlugin;
use Kint\Renderer\TextRenderer;
use Kint\Utils;
use Kint\Zval\Representation\MicrotimeRepresentation;
use Kint\Zval\Value;
class MicrotimePlugin extends Plugin
{
protected $useJs = false;
public function __construct(TextRenderer $r)
{
parent::__construct($r);
if ($this->renderer instanceof PlainRenderer) {
$this->useJs = true;
}
}
public function render(Value $o)
{
$r = $o->getRepresentation('microtime');
if (!$r instanceof MicrotimeRepresentation) {
return;
}
$out = '';
if (0 == $o->depth) {
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL;
}
$out .= $this->renderer->renderHeader($o);
$out .= $this->renderer->renderChildren($o).PHP_EOL;
$indent = \str_repeat(' ', ($o->depth + 1) * $this->renderer->indent_width);
if ($this->useJs) {
$out .= '<span data-kint-microtime-group="'.$r->group.'">';
}
$out .= $indent.$this->renderer->colorType('TIME:').' ';
$out .= $this->renderer->colorValue($r->getDateTime()->format('Y-m-d H:i:s.u')).PHP_EOL;
if (null !== $r->lap) {
$out .= $indent.$this->renderer->colorType('SINCE LAST CALL:').' ';
$lap = \round($r->lap, 4);
if ($this->useJs) {
$lap = '<span class="kint-microtime-lap">'.$lap.'</span>';
}
$out .= $this->renderer->colorValue($lap.'s').'.'.PHP_EOL;
}
if (null !== $r->total) {
$out .= $indent.$this->renderer->colorType('SINCE START:').' ';
$out .= $this->renderer->colorValue(\round($r->total, 4).'s').'.'.PHP_EOL;
}
if (null !== $r->avg) {
$out .= $indent.$this->renderer->colorType('AVERAGE DURATION:').' ';
$avg = \round($r->avg, 4);
if ($this->useJs) {
$avg = '<span class="kint-microtime-avg">'.$avg.'</span>';
}
$out .= $this->renderer->colorValue($avg.'s').'.'.PHP_EOL;
}
$bytes = Utils::getHumanReadableBytes($r->mem);
$mem = $r->mem.' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
$bytes = Utils::getHumanReadableBytes($r->mem_real);
$mem .= ' (real '.\round($bytes['value'], 3).' '.$bytes['unit'].')';
$out .= $indent.$this->renderer->colorType('MEMORY USAGE:').' ';
$out .= $this->renderer->colorValue($mem).'.'.PHP_EOL;
$bytes = Utils::getHumanReadableBytes($r->mem_peak);
$mem = $r->mem_peak.' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
$bytes = Utils::getHumanReadableBytes($r->mem_peak_real);
$mem .= ' (real '.\round($bytes['value'], 3).' '.$bytes['unit'].')';
$out .= $indent.$this->renderer->colorType('PEAK MEMORY USAGE:').' ';
$out .= $this->renderer->colorValue($mem).'.'.PHP_EOL;
if ($this->useJs) {
$out .= '</span>';
}
return $out;
}
public static function renderJs()
{
return RichPlugin::renderJs();
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Text;
use Kint\Renderer\TextRenderer;
use Kint\Zval\Value;
abstract class Plugin
{
protected $renderer;
public function __construct(TextRenderer $r)
{
$this->renderer = $r;
}
/**
* @return null|string
*/
abstract public function render(Value $o);
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Text;
use Kint\Zval\Value;
class RecursionPlugin extends Plugin
{
public function render(Value $o)
{
$out = '';
if (0 == $o->depth) {
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL;
}
$out .= $this->renderer->renderHeader($o).' '.$this->renderer->colorValue('RECURSION').PHP_EOL;
return $out;
}
}

View File

@@ -0,0 +1,111 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer\Text;
use Kint\Zval\MethodValue;
use Kint\Zval\Value;
class TracePlugin extends Plugin
{
public function render(Value $o)
{
$out = '';
if (0 == $o->depth) {
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL;
}
$out .= $this->renderer->renderHeader($o).':'.PHP_EOL;
$indent = \str_repeat(' ', ($o->depth + 1) * $this->renderer->indent_width);
$i = 1;
foreach ($o->value->contents as $frame) {
$framedesc = $indent.\str_pad($i.': ', 4, ' ');
if ($frame->trace['file']) {
$framedesc .= $this->renderer->ideLink($frame->trace['file'], $frame->trace['line']).PHP_EOL;
} else {
$framedesc .= 'PHP internal call'.PHP_EOL;
}
$framedesc .= $indent.' ';
if ($frame->trace['class']) {
$framedesc .= $this->renderer->escape($frame->trace['class']);
if ($frame->trace['object']) {
$framedesc .= $this->renderer->escape('->');
} else {
$framedesc .= '::';
}
}
if (\is_string($frame->trace['function'])) {
$framedesc .= $this->renderer->escape($frame->trace['function']).'(...)';
} elseif ($frame->trace['function'] instanceof MethodValue) {
$framedesc .= $this->renderer->escape($frame->trace['function']->getName());
$framedesc .= '('.$this->renderer->escape($frame->trace['function']->getParams()).')';
}
$out .= $this->renderer->colorType($framedesc).PHP_EOL.PHP_EOL;
if ($source = $frame->getRepresentation('source')) {
$line_wanted = $source->line;
$source = $source->source;
// Trim empty lines from the start and end of the source
foreach ($source as $linenum => $line) {
if (\trim($line) || $linenum === $line_wanted) {
break;
}
unset($source[$linenum]);
}
foreach (\array_reverse($source, true) as $linenum => $line) {
if (\trim($line) || $linenum === $line_wanted) {
break;
}
unset($source[$linenum]);
}
foreach ($source as $lineno => $line) {
if ($lineno == $line_wanted) {
$out .= $indent.$this->renderer->colorValue($this->renderer->escape($line)).PHP_EOL;
} else {
$out .= $indent.$this->renderer->escape($line).PHP_EOL;
}
}
}
++$i;
}
return $out;
}
}

View File

@@ -0,0 +1,350 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Kint\Renderer;
use Kint\Kint;
use Kint\Utils;
use Kint\Zval\InstanceValue;
use Kint\Zval\Value;
class TextRenderer extends Renderer
{
/**
* TextRenderer plugins should be instances of Kint\Renderer\Text\Plugin.
*/
public static $plugins = [
'array_limit' => 'Kint\\Renderer\\Text\\ArrayLimitPlugin',
'blacklist' => 'Kint\\Renderer\\Text\\BlacklistPlugin',
'depth_limit' => 'Kint\\Renderer\\Text\\DepthLimitPlugin',
'microtime' => 'Kint\\Renderer\\Text\\MicrotimePlugin',
'recursion' => 'Kint\\Renderer\\Text\\RecursionPlugin',
'trace' => 'Kint\\Renderer\\Text\\TracePlugin',
];
/**
* Parser plugins must be instanceof one of these or
* it will be removed for performance reasons.
*/
public static $parser_plugin_whitelist = [
'Kint\\Parser\\ArrayLimitPlugin',
'Kint\\Parser\\ArrayObjectPlugin',
'Kint\\Parser\\BlacklistPlugin',
'Kint\\Parser\\MicrotimePlugin',
'Kint\\Parser\\StreamPlugin',
'Kint\\Parser\\TracePlugin',
];
/**
* The maximum length of a string before it is truncated.
*
* Falsey to disable
*
* @var int
*/
public static $strlen_max = 0;
/**
* The default width of the terminal for headers.
*
* @var int
*/
public static $default_width = 80;
/**
* Indentation width.
*
* @var int
*/
public static $default_indent = 4;
/**
* Decorate the header and footer.
*
* @var bool
*/
public static $decorations = true;
/**
* Sort mode for object properties.
*
* @var int
*/
public static $sort = self::SORT_NONE;
public $header_width = 80;
public $indent_width = 4;
protected $plugin_objs = [];
public function __construct()
{
$this->header_width = self::$default_width;
$this->indent_width = self::$default_indent;
}
public function render(Value $o)
{
if ($plugin = $this->getPlugin(self::$plugins, $o->hints)) {
$output = $plugin->render($o);
if (null !== $output && \strlen($output)) {
return $output;
}
}
$out = '';
if (0 == $o->depth) {
$out .= $this->colorTitle($this->renderTitle($o)).PHP_EOL;
}
$out .= $this->renderHeader($o);
$out .= $this->renderChildren($o).PHP_EOL;
return $out;
}
public function renderNothing()
{
if (self::$decorations) {
return $this->colorTitle(
$this->boxText('No argument', $this->header_width)
).PHP_EOL;
}
return $this->colorTitle('No argument').PHP_EOL;
}
public function boxText($text, $width)
{
$out = '┌'.\str_repeat('─', $width - 2).'┐'.PHP_EOL;
if (\strlen($text)) {
$text = Utils::truncateString($text, $width - 4);
$text = \str_pad($text, $width - 4);
$out .= '│ '.$this->escape($text).' │'.PHP_EOL;
}
$out .= '└'.\str_repeat('─', $width - 2).'┘';
return $out;
}
public function renderTitle(Value $o)
{
$name = (string) $o->getName();
if (self::$decorations) {
return $this->boxText($name, $this->header_width);
}
return Utils::truncateString($name, $this->header_width);
}
public function renderHeader(Value $o)
{
$output = [];
if ($o->depth) {
if (null !== ($s = $o->getModifiers())) {
$output[] = $s;
}
if (null !== $o->name) {
$output[] = $this->escape(\var_export($o->name, true));
if (null !== ($s = $o->getOperator())) {
$output[] = $this->escape($s);
}
}
}
if (null !== ($s = $o->getType())) {
if ($o->reference) {
$s = '&'.$s;
}
$output[] = $this->colorType($this->escape($s));
}
if (null !== ($s = $o->getSize())) {
$output[] = '('.$this->escape($s).')';
}
if (null !== ($s = $o->getValueShort())) {
if (self::$strlen_max) {
$s = Utils::truncateString($s, self::$strlen_max);
}
$output[] = $this->colorValue($this->escape($s));
}
return \str_repeat(' ', $o->depth * $this->indent_width).\implode(' ', $output);
}
public function renderChildren(Value $o)
{
if ('array' === $o->type) {
$output = ' [';
} elseif ('object' === $o->type) {
$output = ' (';
} else {
return '';
}
$children = '';
if ($o->value && \is_array($o->value->contents)) {
if ($o instanceof InstanceValue && 'properties' === $o->value->getName()) {
foreach (self::sortProperties($o->value->contents, self::$sort) as $obj) {
$children .= $this->render($obj);
}
} else {
foreach ($o->value->contents as $child) {
$children .= $this->render($child);
}
}
}
if ($children) {
$output .= PHP_EOL.$children;
$output .= \str_repeat(' ', $o->depth * $this->indent_width);
}
if ('array' === $o->type) {
$output .= ']';
} else {
$output .= ')';
}
return $output;
}
public function colorValue($string)
{
return $string;
}
public function colorType($string)
{
return $string;
}
public function colorTitle($string)
{
return $string;
}
public function postRender()
{
if (self::$decorations) {
$output = \str_repeat('═', $this->header_width);
} else {
$output = '';
}
if (!$this->show_trace) {
return $this->colorTitle($output);
}
if ($output) {
$output .= PHP_EOL;
}
return $this->colorTitle($output.$this->calledFrom().PHP_EOL);
}
public function filterParserPlugins(array $plugins)
{
$return = [];
foreach ($plugins as $index => $plugin) {
foreach (self::$parser_plugin_whitelist as $whitelist) {
if ($plugin instanceof $whitelist) {
$return[] = $plugin;
continue 2;
}
}
}
return $return;
}
public function ideLink($file, $line)
{
return $this->escape(Kint::shortenPath($file)).':'.$line;
}
public function escape($string, $encoding = false)
{
return $string;
}
protected function calledFrom()
{
$output = '';
if (isset($this->call_info['callee']['file'])) {
$output .= 'Called from '.$this->ideLink(
$this->call_info['callee']['file'],
$this->call_info['callee']['line']
);
}
if (isset($this->call_info['callee']['function']) && (
!empty($this->call_info['callee']['class']) ||
!\in_array(
$this->call_info['callee']['function'],
['include', 'include_once', 'require', 'require_once'],
true
)
)
) {
$output .= ' [';
if (isset($this->call_info['callee']['class'])) {
$output .= $this->call_info['callee']['class'];
}
if (isset($this->call_info['callee']['type'])) {
$output .= $this->call_info['callee']['type'];
}
$output .= $this->call_info['callee']['function'].'()]';
}
return $output;
}
protected function getPlugin(array $plugins, array $hints)
{
if ($plugins = $this->matchPlugins($plugins, $hints)) {
$plugin = \end($plugins);
if (!isset($this->plugin_objs[$plugin])) {
$this->plugin_objs[$plugin] = new $plugin($this);
}
return $this->plugin_objs[$plugin];
}
}
}