first commit

This commit is contained in:
2024-09-06 13:32:15 -04:00
commit 700e8a2948
2013 changed files with 447887 additions and 0 deletions
+175
View File
@@ -0,0 +1,175 @@
<?php
declare(strict_types=1);
/*
* 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;
/**
* @psalm-type PluginMap array<string, class-string>
*
* @psalm-consistent-constructor
*/
abstract class AbstractRenderer implements RendererInterface
{
public const SORT_NONE = 0;
public const SORT_VISIBILITY = 1;
public const SORT_FULL = 2;
protected $call_info = [];
protected $statics = [];
protected $show_trace = true;
public function setCallInfo(array $info): void
{
if (!isset($info['modifiers']) || !\is_array($info['modifiers'])) {
$info['modifiers'] = [];
}
if (!isset($info['trace']) || !\is_array($info['trace'])) {
$info['trace'] = [];
}
$this->call_info = [
'params' => $info['params'] ?? null,
'modifiers' => $info['modifiers'],
'callee' => $info['callee'] ?? null,
'caller' => $info['caller'] ?? null,
'trace' => $info['trace'],
];
}
public function getCallInfo(): array
{
return $this->call_info;
}
public function setStatics(array $statics): void
{
$this->statics = $statics;
$this->setShowTrace(!empty($statics['display_called_from']));
}
public function getStatics(): array
{
return $this->statics;
}
public function setShowTrace(bool $show_trace): void
{
$this->show_trace = $show_trace;
}
public function getShowTrace(): bool
{
return $this->show_trace;
}
public function filterParserPlugins(array $plugins): array
{
return $plugins;
}
public function preRender(): string
{
return '';
}
public function postRender(): string
{
return '';
}
/**
* Returns the first compatible plugin available.
*
* @psalm-param PluginMap $plugins Array of hints to class strings
* @psalm-param string[] $hints Array of object hints
*
* @psalm-return PluginMap Array of hints to class strings filtered and sorted by object hints
*/
public function matchPlugins(array $plugins, array $hints): array
{
$out = [];
foreach ($hints as $key) {
if (isset($plugins[$key])) {
$out[$key] = $plugins[$key];
}
}
return $out;
}
public static function sortPropertiesFull(Value $a, Value $b): int
{
$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
*
* @return Value[]
*/
public static function sortProperties(array $contents, int $sort): array
{
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, [self::class, 'sortPropertiesFull']);
// no break
default:
return $contents;
}
}
}
+182
View File
@@ -0,0 +1,182 @@
<?php
declare(strict_types=1);
/*
* 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\Value;
use Throwable;
class CliRenderer extends TextRenderer
{
/**
* @var bool enable colors
*/
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.
*
* uses STDOUT by default if it's defined
*
* @var ?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 || !\function_exists('sapi_windows_vt100_support')) {
$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 = (int) \exec('tput cols');
} 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 $string): string
{
if (!$this->colors) {
return $string;
}
return "\x1b[32m".\str_replace("\n", "\x1b[0m\n\x1b[32m", $string)."\x1b[0m";
}
public function colorType(string $string): 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 $string): 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): string
{
if ($this->windows_output) {
return $this->utf8ToWindows(parent::renderTitle($o));
}
return parent::renderTitle($o);
}
public function preRender(): string
{
return PHP_EOL;
}
public function postRender(): string
{
if ($this->windows_output) {
return $this->utf8ToWindows(parent::postRender());
}
return parent::postRender();
}
public function escape(string $string, $encoding = false): string
{
return \str_replace("\x1b", '\\x1b', $string);
}
protected function utf8ToWindows(string $string): string
{
return \str_replace(
['┌', '═', '┐', '│', '└', '─', '┘'],
[' ', '=', ' ', '|', ' ', '-', ' '],
$string
);
}
}
+237
View File
@@ -0,0 +1,237 @@
<?php
declare(strict_types=1);
/*
* 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;
public function __construct()
{
parent::__construct();
$this->setForcePreRender(self::$always_pre_render);
}
public function setCallInfo(array $info): void
{
parent::setCallInfo($info);
if (\in_array('@', $this->call_info['modifiers'], true)) {
$this->setForcePreRender(true);
}
}
public function setStatics(array $statics): void
{
parent::setStatics($statics);
if (!empty($statics['return'])) {
$this->setForcePreRender(true);
}
}
public function setForcePreRender(bool $force_pre_render): void
{
$this->force_pre_render = $force_pre_render;
}
public function getForcePreRender(): bool
{
return $this->force_pre_render;
}
public function shouldPreRender(): bool
{
return $this->getForcePreRender() || self::$needs_pre_render;
}
public function colorValue(string $string): string
{
return '<i>'.$string.'</i>';
}
public function colorType(string $string): string
{
return '<b>'.$string.'</b>';
}
public function colorTitle(string $string): string
{
return '<u>'.$string.'</u>';
}
public function renderTitle(Value $o): string
{
if (self::$disable_utf8) {
return $this->utf8ToHtmlentity(parent::renderTitle($o));
}
return parent::renderTitle($o);
}
public function preRender(): string
{
$output = '';
if ($this->shouldPreRender()) {
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->getForcePreRender()) {
self::$needs_pre_render = false;
}
}
return $output.'<div class="kint-plain">';
}
public function postRender(): string
{
if (self::$disable_utf8) {
return $this->utf8ToHtmlentity(parent::postRender()).'</div>';
}
return parent::postRender().'</div>';
}
public function ideLink(string $file, int $line): string
{
$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 $string, $encoding = false): string
{
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 $string): string
{
return \str_replace(
['┌', '═', '┐', '│', '└', '─', '┘'],
['&#9484;', '&#9552;', '&#9488;', '&#9474;', '&#9492;', '&#9472;', '&#9496;'],
$string
);
}
protected static function renderJs(): string
{
return \file_get_contents(KINT_DIR.'/resources/compiled/shared.js').\file_get_contents(KINT_DIR.'/resources/compiled/plain.js');
}
protected static function renderCss(): string
{
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);
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/*
* 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\Value;
interface RendererInterface
{
public function __construct();
public function render(Value $o): string;
public function renderNothing(): string;
public function setCallInfo(array $info): void;
public function getCallInfo(): array;
public function setStatics(array $statics): void;
public function getStatics(): array;
public function setShowTrace(bool $show_trace): void;
public function getShowTrace(): bool;
public function filterParserPlugins(array $plugins): array;
public function preRender(): string;
public function postRender(): string;
}
+104
View File
@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
/*
* 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\InstanceValue;
use Kint\Zval\Value;
/**
* @psalm-consistent-constructor
*/
abstract class AbstractPlugin implements PluginInterface
{
protected $renderer;
public function __construct(RichRenderer $r)
{
$this->renderer = $r;
}
/**
* @param string $content The replacement for the getValueShort contents
*/
public function renderLockedHeader(Value $o, string $content): string
{
$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())) {
if (RichRenderer::$escape_types) {
$s = $this->renderer->escape($s);
}
if ($o->reference) {
$s = '&amp;'.$s;
}
$header .= '<var>'.$s.'</var>';
if ($o instanceof InstanceValue && isset($o->spl_object_id)) {
$header .= '#'.((int) $o->spl_object_id);
}
$header .= ' ';
}
if (null !== ($s = $o->getSize())) {
if (RichRenderer::$escape_types) {
$s = $this->renderer->escape($s);
}
$header .= '('.$s.') ';
}
$header .= $content;
if (!empty($ap)) {
$header .= '<div class="access-path">'.$this->renderer->escape($ap).'</div>';
}
return $header.'</dt>';
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements ValuePluginInterface
{
public function renderValue(Value $o): string
{
return '<dl>'.$this->renderLockedHeader($o, '<var>Array Limit</var>').'</dl>';
}
}
+62
View File
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements TabPluginInterface
{
/** @psalm-var positive-int */
public static $line_length = 0x10;
/** @psalm-var positive-int */
public static $chunk_length = 0x4;
public function renderTab(Representation $r): ?string
{
if (!\is_string($r->contents)) {
return null;
}
$out = '<pre>';
$lines = \str_split($r->contents, self::$line_length);
foreach ($lines as $index => $line) {
$out .= \sprintf('%08X', $index * self::$line_length).":\t";
$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;
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements ValuePluginInterface
{
public function renderValue(Value $o): string
{
return '<dl>'.$this->renderLockedHeader($o, '<var>Blacklisted</var>').'</dl>';
}
}
+130
View File
@@ -0,0 +1,130 @@
<?php
declare(strict_types=1);
/*
* 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 ClosurePlugin
{
protected static $method_cache = [];
protected $closure_plugin = null;
public function renderValue(Value $o): ?string
{
if ($o instanceof MethodValue) {
return $this->renderMethod($o);
}
if ($o instanceof ClosureValue) {
return parent::renderValue($o);
}
return null;
}
protected function renderMethod(MethodValue $o): string
{
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>';
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements ValuePluginInterface
{
public function renderValue(Value $o): ?string
{
if (!$o instanceof ClosureValue) {
return null;
}
$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> ';
}
$header .= '<var>Closure</var>';
if (isset($o->spl_object_id)) {
$header .= '#'.((int) $o->spl_object_id);
}
$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>';
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements TabPluginInterface, ValuePluginInterface
{
public function renderValue(Value $o): ?string
{
$r = $o->getRepresentation('color');
if (!$r instanceof ColorRepresentation) {
return null;
}
$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): ?string
{
if (!$r instanceof ColorRepresentation) {
return null;
}
$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 null;
}
return '<pre>'.$out.'</pre>';
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements ValuePluginInterface
{
public function renderValue(Value $o): string
{
return '<dl>'.$this->renderLockedHeader($o, '<var>Depth Limit</var>').'</dl>';
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
/*
* 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\MethodDefinitionRepresentation;
use Kint\Zval\Representation\Representation;
class MethodDefinitionPlugin extends AbstractPlugin implements TabPluginInterface
{
public function renderTab(Representation $r): ?string
{
if (!$r instanceof MethodDefinitionRepresentation) {
return null;
}
if (isset($r->contents)) {
$docstring = [];
foreach (\explode("\n", $r->contents) as $line) {
$docstring[] = \trim($line);
}
$docstring = $this->renderer->escape(\implode("\n", $docstring));
}
$addendum = [];
if (isset($r->class) && $r->inherited) {
$addendum[] = 'Inherited from '.$this->renderer->escape($r->class);
}
if (isset($r->file, $r->line)) {
$addendum[] = 'Defined in '.$this->renderer->escape(Kint::shortenPath($r->file)).':'.((int) $r->line);
}
if ($addendum) {
$addendum = '<small>'.\implode("\n", $addendum).'</small>';
if (isset($docstring)) {
$docstring .= "\n\n".$addendum;
} else {
$docstring = $addendum;
}
}
if (!isset($docstring)) {
return null;
}
return '<pre>'.$docstring.'</pre>';
}
}
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements TabPluginInterface
{
public function renderTab(Representation $r): ?string
{
if (!$r instanceof MicrotimeRepresentation || !($dt = $r->getDateTime())) {
return null;
}
$out = $dt->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(): string
{
if (\is_string($out = \file_get_contents(KINT_DIR.'/resources/compiled/microtime.js'))) {
return $out;
}
return '';
}
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/*
* 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);
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements ValuePluginInterface
{
public function renderValue(Value $o): string
{
return '<dl>'.$this->renderLockedHeader($o, '<var>Recursion</var>').'</dl>';
}
}
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
/*
* 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\BlobValue;
use Kint\Zval\SimpleXMLElementValue;
use Kint\Zval\Value;
class SimpleXMLElementPlugin extends AbstractPlugin implements ValuePluginInterface
{
public function renderValue(Value $o): ?string
{
if (!($o instanceof SimpleXMLElementValue)) {
return null;
}
if (!$o->isStringValue() || !empty($o->getRepresentation('attributes')->contents)) {
return null;
}
$b = new BlobValue();
$b->transplant($o);
$b->type = 'string';
$children = $this->renderer->renderChildren($b);
$header = $this->renderer->renderHeader($o);
$header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header);
return '<dl>'.$header.$children.'</dl>';
}
}
+83
View File
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements TabPluginInterface
{
public function renderTab(Representation $r): ?string
{
if (!($r instanceof SourceRepresentation) || empty($r->source)) {
return null;
}
$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>';
}
return null;
}
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/*
* 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
{
public function renderTab(Representation $r): ?string;
}
+141
View File
@@ -0,0 +1,141 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements TabPluginInterface
{
public static $respect_str_length = true;
public function renderTab(Representation $r): string
{
$out = '<pre><table><thead><tr><th></th>';
$firstrow = \reset($r->contents);
foreach ($firstrow->value->contents as $field) {
$out .= '<th>';
if (null !== ($s = $field->getName())) {
$out .= $this->renderer->escape($s);
}
$out .= '</th>';
}
$out .= '</tr></thead><tbody>';
foreach ($r->contents as $row) {
$out .= '<tr><th>';
if (null !== ($s = $row->getName())) {
$out .= $this->renderer->escape($s);
}
$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;
}
}
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements TabPluginInterface
{
public function renderTab(Representation $r): ?string
{
if ($dt = DateTime::createFromFormat('U', (string) $r->contents)) {
return '<pre>'.$dt->setTimeZone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s T').'</pre>';
}
return null;
}
}
@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin implements ValuePluginInterface
{
public function renderValue(Value $o): ?string
{
if (!$o instanceof TraceFrameValue) {
return null;
}
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>';
}
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/*
* 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
{
public function renderValue(Value $o): ?string;
}
+677
View File
@@ -0,0 +1,677 @@
<?php
declare(strict_types=1);
/*
* 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\Renderer\Rich\PluginInterface;
use Kint\Renderer\Rich\TabPluginInterface;
use Kint\Renderer\Rich\ValuePluginInterface;
use Kint\Utils;
use Kint\Zval\BlobValue;
use Kint\Zval\InstanceValue;
use Kint\Zval\Representation\Representation;
use Kint\Zval\Value;
/**
* @psalm-import-type Encoding from BlobValue
* @psalm-import-type PluginMap from AbstractRenderer
*/
class RichRenderer extends AbstractRenderer
{
/**
* RichRenderer value plugins should implement ValuePluginInterface.
*
* @psalm-var PluginMap
*/
public static $value_plugins = [
'array_limit' => Rich\ArrayLimitPlugin::class,
'blacklist' => Rich\BlacklistPlugin::class,
'callable' => Rich\CallablePlugin::class,
'color' => Rich\ColorPlugin::class,
'depth_limit' => Rich\DepthLimitPlugin::class,
'recursion' => Rich\RecursionPlugin::class,
'simplexml_element' => Rich\SimpleXMLElementPlugin::class,
'trace_frame' => Rich\TraceFramePlugin::class,
];
/**
* RichRenderer tab plugins should implement TabPluginInterface.
*
* @psalm-var PluginMap
*/
public static $tab_plugins = [
'binary' => Rich\BinaryPlugin::class,
'color' => Rich\ColorPlugin::class,
'method_definition' => Rich\MethodDefinitionPlugin::class,
'microtime' => Rich\MicrotimePlugin::class,
'source' => Rich\SourcePlugin::class,
'table' => Rich\TablePlugin::class,
'timestamp' => Rich\TimestampPlugin::class,
];
public static $pre_render_sources = [
'script' => [
[self::class, 'renderJs'],
[Rich\MicrotimePlugin::class, 'renderJs'],
],
'style' => [
[self::class, '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;
/**
* Timestamp to print in footer in date() format.
*
* @var ?string
*/
public static $timestamp = null;
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 $use_folder = false;
public function __construct()
{
$this->setUseFolder(self::$folder);
$this->setForcePreRender(self::$always_pre_render);
}
public function setCallInfo(array $info): void
{
parent::setCallInfo($info);
if (\in_array('!', $this->call_info['modifiers'], true)) {
$this->setExpand(true);
$this->setUseFolder(false);
}
if (\in_array('@', $this->call_info['modifiers'], true)) {
$this->setForcePreRender(true);
}
}
public function setStatics(array $statics): void
{
parent::setStatics($statics);
if (!empty($statics['expanded'])) {
$this->setExpand(true);
}
if (!empty($statics['return'])) {
$this->setForcePreRender(true);
}
}
public function setExpand(bool $expand): void
{
$this->expand = $expand;
}
public function getExpand(): bool
{
return $this->expand;
}
public function setForcePreRender(bool $force_pre_render): void
{
$this->force_pre_render = $force_pre_render;
}
public function getForcePreRender(): bool
{
return $this->force_pre_render;
}
public function setUseFolder(bool $use_folder): void
{
$this->use_folder = $use_folder;
}
public function getUseFolder(): bool
{
return $this->use_folder;
}
public function shouldPreRender(): bool
{
return $this->getForcePreRender() || self::$needs_pre_render;
}
public function shouldFolderRender(): bool
{
return $this->getUseFolder() && ($this->getForcePreRender() || self::$needs_folder_render);
}
public function render(Value $o): string
{
if (($plugin = $this->getPlugin(self::$value_plugins, $o->hints)) && $plugin instanceof ValuePluginInterface) {
$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(): string
{
return '<dl><dt><var>No argument</var></dt></dl>';
}
public function renderHeaderWrapper(Value $o, bool $has_children, string $contents): string
{
$out = '<dt';
if ($has_children) {
$out .= ' class="kint-parent';
if ($this->getExpand()) {
$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): string
{
$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 ($o instanceof InstanceValue && isset($o->spl_object_id)) {
$output .= '#'.((int) $o->spl_object_id);
}
$output .= ' ';
}
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): string
{
$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(): string
{
$output = '';
if ($this->shouldPreRender()) {
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->getForcePreRender()) {
self::$needs_pre_render = false;
}
}
if ($this->shouldFolderRender()) {
$output .= $this->renderFolder();
if (!$this->getForcePreRender()) {
self::$needs_folder_render = false;
}
}
$output .= '<div class="kint-rich';
if ($this->getUseFolder()) {
$output .= ' kint-file';
}
$output .= '">';
return $output;
}
public function postRender(): string
{
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>';
}
$output .= $this->calledFrom();
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 .= ' [';
$output .= $step['class'] ?? '';
$output .= $step['type'] ?? '';
$output .= $step['function'].'()]';
}
}
$output .= '</ol>';
}
$output .= '</footer></div>';
return $output;
}
/**
* @psalm-param Encoding $encoding
*/
public function escape(string $string, $encoding = false): string
{
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(string $file, int $line): string
{
$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 calledFrom(): string
{
$output = '';
if (isset($this->call_info['callee']['file'])) {
$output .= ' '.$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 .= ' [';
$output .= $this->call_info['callee']['class'] ?? '';
$output .= $this->call_info['callee']['type'] ?? '';
$output .= $this->call_info['callee']['function'].'()]';
}
if ('' !== $output) {
$output = 'Called from'.$output;
}
if (null !== self::$timestamp) {
$output .= ' '.\date(self::$timestamp);
}
return $output;
}
protected function renderTab(Value $o, Representation $rep): string
{
if (($plugin = $this->getPlugin(self::$tab_plugins, $rep->hints)) && $plugin instanceof TabPluginInterface) {
$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 !== ($vs = $o->getValueShort()) && BlobValue::strlen($vs) > 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 '';
}
/**
* @psalm-param PluginMap $plugins
* @psalm-param string[] $hints
*/
protected function getPlugin(array $plugins, array $hints): ?PluginInterface
{
if ($plugins = $this->matchPlugins($plugins, $hints)) {
$plugin = \end($plugins);
if (!isset($this->plugin_objs[$plugin]) && \is_subclass_of($plugin, PluginInterface::class)) {
$this->plugin_objs[$plugin] = new $plugin($this);
}
return $this->plugin_objs[$plugin];
}
return null;
}
protected static function renderJs(): string
{
return \file_get_contents(KINT_DIR.'/resources/compiled/shared.js').\file_get_contents(KINT_DIR.'/resources/compiled/rich.js');
}
protected static function renderCss(): string
{
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(): string
{
return '<div class="kint-rich kint-folder"><dl><dt class="kint-parent"><nav></nav>Kint</dt><dd class="kint-foldout"></dd></dl></div>';
}
}
+63
View File
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/*
* 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;
/**
* @psalm-consistent-constructor
*/
abstract class AbstractPlugin implements PluginInterface
{
protected $renderer;
public function __construct(TextRenderer $r)
{
$this->renderer = $r;
}
public function renderLockedHeader(Value $o, string $content = null): string
{
$out = '';
if (0 == $o->depth) {
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL;
}
$out .= $this->renderer->renderHeader($o);
if (null !== $content) {
$out .= ' '.$this->renderer->colorValue($content);
}
$out .= PHP_EOL;
return $out;
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin
{
public function render(Value $o): string
{
return $this->renderLockedHeader($o, 'ARRAY LIMIT');
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin
{
public function render(Value $o): string
{
return $this->renderLockedHeader($o, 'BLACKLISTED');
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin
{
public function render(Value $o): string
{
return $this->renderLockedHeader($o, 'DEPTH LIMIT');
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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 EnumPlugin extends AbstractPlugin
{
public function render(Value $o): string
{
return $this->renderLockedHeader($o);
}
}
+130
View File
@@ -0,0 +1,130 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin
{
protected $useJs = false;
public function __construct(TextRenderer $r)
{
parent::__construct($r);
if ($this->renderer instanceof PlainRenderer) {
$this->useJs = true;
}
}
public function render(Value $o): ?string
{
$r = $o->getRepresentation('microtime');
if (!$r instanceof MicrotimeRepresentation || !($dt = $r->getDateTime())) {
return null;
}
$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($dt->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(): string
{
return RichPlugin::renderJs();
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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;
interface PluginInterface
{
public function __construct(TextRenderer $r);
public function render(Value $o): ?string;
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin
{
public function render(Value $o): string
{
return $this->renderLockedHeader($o, 'RECURSION');
}
}
+115
View File
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
/*
* 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 AbstractPlugin
{
public function render(Value $o): string
{
$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) {
if (null !== ($s = $frame->trace['function']->getName())) {
$framedesc .= $this->renderer->escape($s);
$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;
}
}
+391
View File
@@ -0,0 +1,391 @@
<?php
declare(strict_types=1);
/*
* 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\Parser;
use Kint\Renderer\Text\PluginInterface;
use Kint\Utils;
use Kint\Zval\InstanceValue;
use Kint\Zval\Value;
/**
* @psalm-import-type Encoding from \Kint\Zval\BlobValue
* @psalm-import-type PluginMap from AbstractRenderer
*/
class TextRenderer extends AbstractRenderer
{
/**
* TextRenderer plugins should implement PluginInterface.
*
* @psalm-var PluginMap
*/
public static $plugins = [
'array_limit' => Text\ArrayLimitPlugin::class,
'blacklist' => Text\BlacklistPlugin::class,
'depth_limit' => Text\DepthLimitPlugin::class,
'enum' => Text\EnumPlugin::class,
'microtime' => Text\MicrotimePlugin::class,
'recursion' => Text\RecursionPlugin::class,
'trace' => Text\TracePlugin::class,
];
/**
* Parser plugins must be instanceof one of these or
* it will be removed for performance reasons.
*
* @psalm-var class-string[]
*/
public static $parser_plugin_whitelist = [
Parser\ArrayLimitPlugin::class,
Parser\ArrayObjectPlugin::class,
Parser\BlacklistPlugin::class,
Parser\EnumPlugin::class,
Parser\MicrotimePlugin::class,
Parser\StreamPlugin::class,
Parser\TracePlugin::class,
];
/**
* 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;
/**
* Timestamp to print in footer in date() format.
*
* @var ?string
*/
public static $timestamp = null;
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): string
{
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(): string
{
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(string $text, int $width): string
{
$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): string
{
$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): string
{
$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;
}
$s = $this->colorType($this->escape($s));
if ($o instanceof InstanceValue && isset($o->spl_object_id)) {
$s .= '#'.((int) $o->spl_object_id);
}
$output[] = $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): string
{
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 $string): string
{
return $string;
}
public function colorType(string $string): string
{
return $string;
}
public function colorTitle(string $string): string
{
return $string;
}
public function postRender(): string
{
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): array
{
$return = [];
foreach ($plugins as $plugin) {
foreach (self::$parser_plugin_whitelist as $whitelist) {
if ($plugin instanceof $whitelist) {
$return[] = $plugin;
continue 2;
}
}
}
return $return;
}
public function ideLink(string $file, int $line): string
{
return $this->escape(Kint::shortenPath($file)).':'.$line;
}
/**
* @psalm-param Encoding $encoding
*/
public function escape(string $string, $encoding = false): string
{
return $string;
}
protected function calledFrom(): string
{
$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 .= ' [';
$output .= $this->call_info['callee']['class'] ?? '';
$output .= $this->call_info['callee']['type'] ?? '';
$output .= $this->call_info['callee']['function'].'()]';
}
if (null !== self::$timestamp) {
if (\strlen($output)) {
$output .= ' ';
}
$output .= \date(self::$timestamp);
}
return $output;
}
/**
* @psalm-param PluginMap $plugins
* @psalm-param string[] $hints
*/
protected function getPlugin(array $plugins, array $hints): ?PluginInterface
{
if ($plugins = $this->matchPlugins($plugins, $hints)) {
$plugin = \end($plugins);
if (!isset($this->plugin_objs[$plugin]) && \is_subclass_of($plugin, PluginInterface::class)) {
$this->plugin_objs[$plugin] = new $plugin($this);
}
return $this->plugin_objs[$plugin];
}
return null;
}
}