first commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?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;
|
||||
|
||||
abstract class AbstractRenderer implements ConstructableRendererInterface
|
||||
{
|
||||
public static ?string $js_nonce = null;
|
||||
public static ?string $css_nonce = null;
|
||||
|
||||
/** @psalm-var ?non-empty-string */
|
||||
public static ?string $file_link_format = null;
|
||||
|
||||
protected bool $show_trace = true;
|
||||
protected ?array $callee = null;
|
||||
protected array $trace = [];
|
||||
|
||||
protected bool $render_spl_ids = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function shouldRenderObjectIds(): bool
|
||||
{
|
||||
return $this->render_spl_ids;
|
||||
}
|
||||
|
||||
public function setCallInfo(array $info): void
|
||||
{
|
||||
$this->callee = $info['callee'] ?? null;
|
||||
$this->trace = $info['trace'] ?? [];
|
||||
}
|
||||
|
||||
public function setStatics(array $statics): void
|
||||
{
|
||||
$this->show_trace = !empty($statics['display_called_from']);
|
||||
}
|
||||
|
||||
public function filterParserPlugins(array $plugins): array
|
||||
{
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
public function preRender(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function postRender(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function getFileLink(string $file, int $line): ?string
|
||||
{
|
||||
if (null === self::$file_link_format) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return \str_replace(['%f', '%l'], [$file, $line], self::$file_link_format);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
trait AssetRendererTrait
|
||||
{
|
||||
public static ?string $theme = null;
|
||||
|
||||
/** @psalm-var array{js?:string, css?:array<path, string|false>} */
|
||||
private static array $assetCache = [];
|
||||
|
||||
/** @psalm-api */
|
||||
public static function renderJs(): string
|
||||
{
|
||||
if (!isset(self::$assetCache['js'])) {
|
||||
self::$assetCache['js'] = \file_get_contents(KINT_DIR.'/resources/compiled/main.js');
|
||||
}
|
||||
|
||||
return self::$assetCache['js'];
|
||||
}
|
||||
|
||||
/** @psalm-api */
|
||||
public static function renderCss(): ?string
|
||||
{
|
||||
if (!isset(self::$theme)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset(self::$assetCache['css'][self::$theme])) {
|
||||
if (\file_exists(KINT_DIR.'/resources/compiled/'.self::$theme)) {
|
||||
self::$assetCache['css'][self::$theme] = \file_get_contents(KINT_DIR.'/resources/compiled/'.self::$theme);
|
||||
} elseif (\file_exists(self::$theme)) {
|
||||
self::$assetCache['css'][self::$theme] = \file_get_contents(self::$theme);
|
||||
} else {
|
||||
self::$assetCache['css'][self::$theme] = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (false === self::$assetCache['css'][self::$theme]) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::$assetCache['css'][self::$theme];
|
||||
}
|
||||
}
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Throwable;
|
||||
|
||||
class CliRenderer extends TextRenderer
|
||||
{
|
||||
/**
|
||||
* @var bool enable colors
|
||||
*/
|
||||
public static bool $cli_colors = true;
|
||||
|
||||
/**
|
||||
* Detects the terminal width on startup.
|
||||
*/
|
||||
public static bool $detect_width = true;
|
||||
|
||||
/**
|
||||
* The minimum width to detect terminal size as.
|
||||
*
|
||||
* Less than this is ignored and falls back to default width.
|
||||
*/
|
||||
public static int $min_terminal_width = 40;
|
||||
|
||||
/**
|
||||
* Forces utf8 output on windows.
|
||||
*/
|
||||
public static bool $force_utf8 = false;
|
||||
|
||||
/**
|
||||
* Which stream to check for VT100 support on windows.
|
||||
*
|
||||
* uses STDOUT by default if it's defined
|
||||
*
|
||||
* @psalm-var ?resource
|
||||
*/
|
||||
public static $windows_stream = null;
|
||||
|
||||
protected static ?int $terminal_width = null;
|
||||
|
||||
protected bool $windows_output = false;
|
||||
|
||||
protected bool $colors = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if (!self::$force_utf8 && KINT_WIN) {
|
||||
if (!\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 (null === self::$terminal_width) {
|
||||
if (self::$detect_width) {
|
||||
try {
|
||||
$tput = KINT_WIN ? \exec('tput cols 2>nul') : \exec('tput cols 2>/dev/null');
|
||||
if ((bool) $tput) {
|
||||
/**
|
||||
* @psalm-suppress InvalidCast
|
||||
* Psalm bug #11080
|
||||
*/
|
||||
self::$terminal_width = (int) $tput;
|
||||
}
|
||||
} catch (Throwable $t) {
|
||||
self::$terminal_width = self::$default_width;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset(self::$terminal_width) || 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(AbstractValue $v): string
|
||||
{
|
||||
if ($this->windows_output) {
|
||||
return $this->utf8ToWindows(parent::renderTitle($v));
|
||||
}
|
||||
|
||||
return parent::renderTitle($v);
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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;
|
||||
|
||||
interface ConstructableRendererInterface extends RendererInterface
|
||||
{
|
||||
public function __construct();
|
||||
}
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
<?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\Utils;
|
||||
use Kint\Value\AbstractValue;
|
||||
|
||||
class PlainRenderer extends TextRenderer
|
||||
{
|
||||
use AssetRendererTrait;
|
||||
|
||||
public static array $pre_render_sources = [
|
||||
'script' => [
|
||||
[self::class, 'renderJs'],
|
||||
],
|
||||
'style' => [
|
||||
[self::class, 'renderCss'],
|
||||
],
|
||||
'raw' => [],
|
||||
];
|
||||
|
||||
/**
|
||||
* Output htmlentities instead of utf8.
|
||||
*/
|
||||
public static bool $disable_utf8 = false;
|
||||
|
||||
public static bool $needs_pre_render = true;
|
||||
|
||||
public static bool $always_pre_render = false;
|
||||
|
||||
protected bool $force_pre_render = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
self::$theme ??= 'plain.css';
|
||||
$this->setForcePreRender(self::$always_pre_render);
|
||||
}
|
||||
|
||||
public function setCallInfo(array $info): void
|
||||
{
|
||||
parent::setCallInfo($info);
|
||||
|
||||
if (\in_array('@', $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(AbstractValue $v): string
|
||||
{
|
||||
if (self::$disable_utf8) {
|
||||
return $this->utf8ToHtmlentity(parent::renderTitle($v));
|
||||
}
|
||||
|
||||
return parent::renderTitle($v);
|
||||
}
|
||||
|
||||
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"';
|
||||
if (null !== self::$js_nonce) {
|
||||
$output .= ' nonce="'.\htmlspecialchars(self::$js_nonce).'"';
|
||||
}
|
||||
$output .= '>'.$contents.'</script>';
|
||||
break;
|
||||
case 'style':
|
||||
$output .= '<style class="kint-plain-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;
|
||||
}
|
||||
}
|
||||
|
||||
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(Utils::shortenPath($file)).':'.$line;
|
||||
$ideLink = self::getFileLink($file, $line);
|
||||
|
||||
if (null === $ideLink) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
return '<a href="'.$this->escape($ideLink).'">'.$path.'</a>';
|
||||
}
|
||||
|
||||
public function escape(string $string, $encoding = false): string
|
||||
{
|
||||
if (false === $encoding) {
|
||||
$encoding = Utils::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(
|
||||
['┌', '═', '┐', '│', '└', '─', '┘'],
|
||||
['┌', '═', '┐', '│', '└', '─', '┘'],
|
||||
$string
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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\Value\AbstractValue;
|
||||
|
||||
interface RendererInterface
|
||||
{
|
||||
public function render(AbstractValue $v): string;
|
||||
|
||||
public function shouldRenderObjectIds(): bool;
|
||||
|
||||
public function setCallInfo(array $info): void;
|
||||
|
||||
public function setStatics(array $statics): void;
|
||||
|
||||
public function filterParserPlugins(array $plugins): array;
|
||||
|
||||
public function preRender(): string;
|
||||
|
||||
public function postRender(): string;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Kint\Value\Context\ClassDeclaredContext;
|
||||
use Kint\Value\Context\PropertyContext;
|
||||
use Kint\Value\InstanceValue;
|
||||
|
||||
abstract class AbstractPlugin implements PluginInterface
|
||||
{
|
||||
protected RichRenderer $renderer;
|
||||
|
||||
public function __construct(RichRenderer $r)
|
||||
{
|
||||
$this->renderer = $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content The replacement for the getValueShort contents
|
||||
*/
|
||||
public function renderLockedHeader(AbstractValue $v, string $content): string
|
||||
{
|
||||
$header = '<dt class="kint-parent kint-locked">';
|
||||
|
||||
$c = $v->getContext();
|
||||
|
||||
if (RichRenderer::$access_paths && $c->getDepth() > 0 && null !== ($ap = $c->getAccessPath())) {
|
||||
$header .= '<span class="kint-access-path-trigger" title="Show access path">⇄</span>';
|
||||
}
|
||||
|
||||
$header .= '<nav></nav>';
|
||||
|
||||
if ($c instanceof ClassDeclaredContext) {
|
||||
$header .= '<var>'.$c->getModifiers().'</var> ';
|
||||
}
|
||||
|
||||
$header .= '<dfn>'.$this->renderer->escape($v->getDisplayName()).'</dfn> ';
|
||||
|
||||
if ($c instanceof PropertyContext && null !== ($s = $c->getHooks())) {
|
||||
$header .= '<var>'.$this->renderer->escape($s).'</var> ';
|
||||
}
|
||||
|
||||
if (null !== ($s = $c->getOperator())) {
|
||||
$header .= $this->renderer->escape($s, 'ASCII').' ';
|
||||
}
|
||||
|
||||
$s = $v->getDisplayType();
|
||||
|
||||
if (RichRenderer::$escape_types) {
|
||||
$s = $this->renderer->escape($s);
|
||||
}
|
||||
|
||||
if ($c->isRef()) {
|
||||
$s = '&'.$s;
|
||||
}
|
||||
|
||||
$header .= '<var>'.$s.'</var>';
|
||||
|
||||
if ($v instanceof InstanceValue && $this->renderer->shouldRenderObjectIds()) {
|
||||
$header .= '#'.$v->getSplObjectId();
|
||||
}
|
||||
|
||||
$header .= ' ';
|
||||
|
||||
if (null !== ($s = $v->getDisplaySize())) {
|
||||
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,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\Value\AbstractValue;
|
||||
use Kint\Value\Representation\BinaryRepresentation;
|
||||
use Kint\Value\Representation\RepresentationInterface;
|
||||
|
||||
class BinaryPlugin extends AbstractPlugin implements TabPluginInterface
|
||||
{
|
||||
/** @psalm-var positive-int */
|
||||
public static int $line_length = 0x10;
|
||||
/** @psalm-var positive-int */
|
||||
public static int $chunk_length = 0x2;
|
||||
|
||||
public function renderTab(RepresentationInterface $r, AbstractValue $v): ?string
|
||||
{
|
||||
if (!$r instanceof BinaryRepresentation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$out = '<pre>';
|
||||
|
||||
$lines = \str_split($r->getValue(), 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, ' '), 2 * self::$chunk_length);
|
||||
|
||||
$out .= \implode(' ', $chunks);
|
||||
$out .= "\t".\preg_replace('/[^\\x20-\\x7E]/', '.', $line)."\n";
|
||||
}
|
||||
|
||||
$out .= '</pre>';
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -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\Utils;
|
||||
use Kint\Value\AbstractValue;
|
||||
use Kint\Value\MethodValue;
|
||||
use Kint\Value\Representation\CallableDefinitionRepresentation;
|
||||
use Kint\Value\Representation\RepresentationInterface;
|
||||
|
||||
class CallableDefinitionPlugin extends AbstractPlugin implements TabPluginInterface
|
||||
{
|
||||
public function renderTab(RepresentationInterface $r, AbstractValue $v): ?string
|
||||
{
|
||||
if (!$r instanceof CallableDefinitionRepresentation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$docstring = [];
|
||||
|
||||
if ($v instanceof MethodValue) {
|
||||
$c = $v->getContext();
|
||||
|
||||
if ($c->inherited) {
|
||||
$docstring[] = 'Inherited from '.$this->renderer->escape($c->owner_class);
|
||||
}
|
||||
}
|
||||
|
||||
$docstring[] = 'Defined in '.$this->renderer->escape(Utils::shortenPath($r->getFileName())).':'.$r->getLine();
|
||||
|
||||
$docstring = '<small>'.\implode("\n", $docstring).'</small>';
|
||||
|
||||
if (null !== ($trimmed = $r->getDocstringTrimmed())) {
|
||||
$docstring = $this->renderer->escape($trimmed)."\n\n".$docstring;
|
||||
}
|
||||
|
||||
return '<pre>'.$docstring.'</pre>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Kint\Value\Context\MethodContext;
|
||||
use Kint\Value\MethodValue;
|
||||
|
||||
class CallablePlugin extends AbstractPlugin implements ValuePluginInterface
|
||||
{
|
||||
protected static array $method_cache = [];
|
||||
|
||||
public function renderValue(AbstractValue $v): ?string
|
||||
{
|
||||
if (!$v instanceof MethodValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$c = $v->getContext();
|
||||
|
||||
if (!$c instanceof MethodContext) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset(self::$method_cache[$c->owner_class][$c->name])) {
|
||||
$children = $this->renderer->renderChildren($v);
|
||||
|
||||
$header = '<var>'.$c->getModifiers();
|
||||
|
||||
if ($v->getCallableBag()->return_reference) {
|
||||
$header .= ' &';
|
||||
}
|
||||
|
||||
$header .= '</var> ';
|
||||
|
||||
$function = $this->renderer->escape($v->getDisplayName());
|
||||
|
||||
if (null !== ($url = $v->getPhpDocUrl())) {
|
||||
$function = '<a href="'.$url.'" target=_blank>'.$function.'</a>';
|
||||
}
|
||||
|
||||
$header .= '<dfn>'.$function.'</dfn>';
|
||||
|
||||
if (null !== ($rt = $v->getCallableBag()->returntype)) {
|
||||
$header .= ': <var>';
|
||||
$header .= $this->renderer->escape($rt).'</var>';
|
||||
} elseif (null !== ($ds = $v->getCallableBag()->docstring)) {
|
||||
if (\preg_match('/@return\\s+(.*)\\r?\\n/m', $ds, $matches)) {
|
||||
if (\trim($matches[1])) {
|
||||
$header .= ': <var>'.$this->renderer->escape(\trim($matches[1])).'</var>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== ($s = $v->getDisplayValue())) {
|
||||
if (RichRenderer::$strlen_max) {
|
||||
$s = Utils::truncateString($s, RichRenderer::$strlen_max);
|
||||
}
|
||||
$header .= ' '.$this->renderer->escape($s);
|
||||
}
|
||||
|
||||
self::$method_cache[$c->owner_class][$c->name] = [
|
||||
'header' => $header,
|
||||
'children' => $children,
|
||||
];
|
||||
}
|
||||
|
||||
$children = self::$method_cache[$c->owner_class][$c->name]['children'];
|
||||
|
||||
$header = $this->renderer->renderHeaderWrapper(
|
||||
$c,
|
||||
(bool) \strlen($children),
|
||||
self::$method_cache[$c->owner_class][$c->name]['header']
|
||||
);
|
||||
|
||||
return '<dl>'.$header.$children.'</dl>';
|
||||
}
|
||||
}
|
||||
@@ -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\Value\AbstractValue;
|
||||
use Kint\Value\Representation\ColorRepresentation;
|
||||
use Kint\Value\Representation\RepresentationInterface;
|
||||
|
||||
class ColorPlugin extends AbstractPlugin implements TabPluginInterface, ValuePluginInterface
|
||||
{
|
||||
public function renderValue(AbstractValue $v): ?string
|
||||
{
|
||||
$r = $v->getRepresentation('color');
|
||||
|
||||
if (!$r instanceof ColorRepresentation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$children = $this->renderer->renderChildren($v);
|
||||
|
||||
$header = $this->renderer->renderHeader($v);
|
||||
$header .= '<div class="kint-color-preview"><div style="background:';
|
||||
$header .= $r->getColor(ColorRepresentation::COLOR_RGBA);
|
||||
$header .= '"></div></div>';
|
||||
|
||||
$header = $this->renderer->renderHeaderWrapper($v->getContext(), (bool) \strlen($children), $header);
|
||||
|
||||
return '<dl>'.$header.$children.'</dl>';
|
||||
}
|
||||
|
||||
public function renderTab(RepresentationInterface $r, AbstractValue $v): ?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,49 @@
|
||||
<?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\Value\AbstractValue;
|
||||
|
||||
class LockPlugin extends AbstractPlugin implements ValuePluginInterface
|
||||
{
|
||||
public function renderValue(AbstractValue $v): ?string
|
||||
{
|
||||
switch ($v->getHint()) {
|
||||
case 'blacklist':
|
||||
return '<dl>'.$this->renderLockedHeader($v, '<var>Blacklisted</var>').'</dl>';
|
||||
case 'recursion':
|
||||
return '<dl>'.$this->renderLockedHeader($v, '<var>Recursion</var>').'</dl>';
|
||||
case 'depth_limit':
|
||||
return '<dl>'.$this->renderLockedHeader($v, '<var>Depth Limit</var>').'</dl>';
|
||||
case 'array_limit':
|
||||
return '<dl>'.$this->renderLockedHeader($v, '<var>Array Limit</var>').'</dl>';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Kint\Value\Representation\MicrotimeRepresentation;
|
||||
use Kint\Value\Representation\RepresentationInterface;
|
||||
|
||||
class MicrotimePlugin extends AbstractPlugin implements TabPluginInterface
|
||||
{
|
||||
public function renderTab(RepresentationInterface $r, AbstractValue $v): ?string
|
||||
{
|
||||
if (!$r instanceof MicrotimeRepresentation || !($dt = $r->getDateTime())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$out = $dt->format('Y-m-d H:i:s.u');
|
||||
if (null !== ($lap = $r->getLapTime())) {
|
||||
$out .= '<br><b>SINCE LAST CALL:</b> <span class="kint-microtime-lap">'.\round($lap, 4).'</span>s.';
|
||||
}
|
||||
if (null !== ($total = $r->getTotalTime())) {
|
||||
$out .= '<br><b>SINCE START:</b> '.\round($total, 4).'s.';
|
||||
}
|
||||
if (null !== ($avg = $r->getAverageTime())) {
|
||||
$out .= '<br><b>AVERAGE DURATION:</b> <span class="kint-microtime-avg">'.\round($avg, 4).'</span>s.';
|
||||
}
|
||||
|
||||
$bytes = Utils::getHumanReadableBytes($r->getMemoryUsage());
|
||||
$out .= '<br><b>MEMORY USAGE:</b> '.$r->getMemoryUsage().' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
|
||||
$bytes = Utils::getHumanReadableBytes($r->getMemoryUsageReal());
|
||||
$out .= ' (real '.\round($bytes['value'], 3).' '.$bytes['unit'].')';
|
||||
|
||||
$bytes = Utils::getHumanReadableBytes($r->getMemoryPeakUsage());
|
||||
$out .= '<br><b>PEAK MEMORY USAGE:</b> '.$r->getMemoryPeakUsage().' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
|
||||
$bytes = Utils::getHumanReadableBytes($r->getMemoryPeakUsageReal());
|
||||
$out .= ' (real '.\round($bytes['value'], 3).' '.$bytes['unit'].')';
|
||||
|
||||
return '<pre data-kint-microtime-group="'.$r->getGroup().'">'.$out.'</pre>';
|
||||
}
|
||||
}
|
||||
@@ -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,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\Value\AbstractValue;
|
||||
use Kint\Value\Representation\ProfileRepresentation;
|
||||
use Kint\Value\Representation\RepresentationInterface;
|
||||
|
||||
class ProfilePlugin extends AbstractPlugin implements TabPluginInterface
|
||||
{
|
||||
public function renderTab(RepresentationInterface $r, AbstractValue $v): ?string
|
||||
{
|
||||
if (!$r instanceof ProfileRepresentation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$out = '<pre>';
|
||||
|
||||
$out .= 'Complexity: '.$r->complexity.PHP_EOL;
|
||||
if (isset($r->instance_counts)) {
|
||||
$out .= 'Instance repetitions: '.\var_export($r->instance_counts, true).PHP_EOL;
|
||||
}
|
||||
if (isset($r->instance_complexity)) {
|
||||
$out .= 'Instance complexity: '.\var_export($r->instance_complexity, true).PHP_EOL;
|
||||
}
|
||||
|
||||
$out .= '</pre>';
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Kint\Value\Representation\RepresentationInterface;
|
||||
use Kint\Value\Representation\SourceRepresentation;
|
||||
|
||||
class SourcePlugin extends AbstractPlugin implements TabPluginInterface
|
||||
{
|
||||
public function renderTab(RepresentationInterface $r, AbstractValue $v): ?string
|
||||
{
|
||||
if (!$r instanceof SourceRepresentation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$source = $r->getSourceLines();
|
||||
|
||||
// Trim empty lines from the start and end of the source
|
||||
foreach ($source as $linenum => $line) {
|
||||
if (\strlen(\trim($line)) || $linenum === $r->getLine()) {
|
||||
break;
|
||||
}
|
||||
|
||||
unset($source[$linenum]);
|
||||
}
|
||||
|
||||
foreach (\array_reverse($source, true) as $linenum => $line) {
|
||||
if (\strlen(\trim($line)) || $linenum === $r->getLine()) {
|
||||
break;
|
||||
}
|
||||
|
||||
unset($source[$linenum]);
|
||||
}
|
||||
|
||||
$output = '';
|
||||
|
||||
foreach ($source as $linenum => $line) {
|
||||
if ($linenum === $r->getLine()) {
|
||||
$output .= '<div class="kint-highlight">'.$this->renderer->escape($line)."\n".'</div>';
|
||||
} else {
|
||||
$output .= '<div>'.$this->renderer->escape($line)."\n".'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($output) {
|
||||
$data = '';
|
||||
if ($r->showFileName()) {
|
||||
$data = ' data-kint-filename="'.$this->renderer->escape($r->getFileName()).'"';
|
||||
}
|
||||
|
||||
return '<div><pre class="kint-source"'.$data.' style="counter-reset: kint-l '.((int) \array_key_first($source) - 1).';">'.$output.'</pre></div><div></div>';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Kint\Value\Representation\RepresentationInterface;
|
||||
|
||||
interface TabPluginInterface extends PluginInterface
|
||||
{
|
||||
public function renderTab(RepresentationInterface $r, AbstractValue $v): ?string;
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Kint\Value\ArrayValue;
|
||||
use Kint\Value\FixedWidthValue;
|
||||
use Kint\Value\Representation\RepresentationInterface;
|
||||
use Kint\Value\Representation\TableRepresentation;
|
||||
use Kint\Value\StringValue;
|
||||
|
||||
class TablePlugin extends AbstractPlugin implements TabPluginInterface
|
||||
{
|
||||
public static bool $respect_str_length = true;
|
||||
|
||||
public function renderTab(RepresentationInterface $r, AbstractValue $v): ?string
|
||||
{
|
||||
if (!$r instanceof TableRepresentation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$contents = $r->getContents();
|
||||
|
||||
$firstrow = \reset($contents);
|
||||
|
||||
if (!$firstrow instanceof ArrayValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$out = '<pre><table><thead><tr><th></th>';
|
||||
|
||||
foreach ($firstrow->getContents() as $field) {
|
||||
$out .= '<th>'.$this->renderer->escape($field->getDisplayName()).'</th>';
|
||||
}
|
||||
|
||||
$out .= '</tr></thead><tbody>';
|
||||
|
||||
foreach ($contents as $row) {
|
||||
if (!$row instanceof ArrayValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$out .= '<tr><th>'.$this->renderer->escape($row->getDisplayName()).'</th>';
|
||||
|
||||
foreach ($row->getContents() as $field) {
|
||||
$ref = $field->getContext()->isRef() ? '&' : '';
|
||||
$type = $this->renderer->escape($field->getDisplayType());
|
||||
|
||||
$out .= '<td title="'.$ref.$type;
|
||||
|
||||
if (null !== ($size = $field->getDisplaySize())) {
|
||||
$size = $this->renderer->escape($size);
|
||||
$out .= ' ('.$size.')';
|
||||
}
|
||||
|
||||
$out .= '">';
|
||||
|
||||
if ($field instanceof FixedWidthValue) {
|
||||
if (null === ($dv = $field->getDisplayValue())) {
|
||||
$out .= '<var>'.$ref.'null</var>';
|
||||
} elseif ('boolean' === $field->getType()) {
|
||||
$out .= '<var>'.$ref.$dv.'</var>';
|
||||
} else {
|
||||
$out .= $dv;
|
||||
}
|
||||
} elseif ($field instanceof StringValue) {
|
||||
if (false !== $field->getEncoding()) {
|
||||
$val = $field->getValueUtf8();
|
||||
|
||||
if (RichRenderer::$strlen_max && self::$respect_str_length) {
|
||||
$val = Utils::truncateString($val, RichRenderer::$strlen_max, 'UTF-8');
|
||||
}
|
||||
|
||||
$out .= $this->renderer->escape($val);
|
||||
} else {
|
||||
$out .= '<var>'.$ref.$type.'</var>';
|
||||
}
|
||||
} elseif ($field instanceof ArrayValue) {
|
||||
$out .= '<var>'.$ref.'array</var> ('.$field->getSize().')';
|
||||
} else {
|
||||
$out .= '<var>'.$ref.$type.'</var>';
|
||||
if (null !== $size) {
|
||||
$out .= ' ('.$size.')';
|
||||
}
|
||||
}
|
||||
|
||||
if ($field->flags & AbstractValue::FLAG_BLACKLIST) {
|
||||
$out .= ' <var>Blacklisted</var>';
|
||||
} elseif ($field->flags & AbstractValue::FLAG_RECURSION) {
|
||||
$out .= ' <var>Recursion</var>';
|
||||
} elseif ($field->flags & AbstractValue::FLAG_DEPTH_LIMIT) {
|
||||
$out .= ' <var>Depth Limit</var>';
|
||||
}
|
||||
|
||||
$out .= '</td>';
|
||||
}
|
||||
|
||||
$out .= '</tr>';
|
||||
}
|
||||
|
||||
$out .= '</tbody></table></pre>';
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Kint\Value\MethodValue;
|
||||
use Kint\Value\TraceFrameValue;
|
||||
|
||||
class TraceFramePlugin extends AbstractPlugin implements ValuePluginInterface
|
||||
{
|
||||
public function renderValue(AbstractValue $v): ?string
|
||||
{
|
||||
if (!$v instanceof TraceFrameValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (null !== ($file = $v->getFile()) && null !== ($line = $v->getLine())) {
|
||||
$header = '<var>'.$this->renderer->ideLink($file, $line).'</var> ';
|
||||
} else {
|
||||
$header = '<var>PHP internal call</var> ';
|
||||
}
|
||||
|
||||
if ($callable = $v->getCallable()) {
|
||||
if ($callable instanceof MethodValue) {
|
||||
$function = $callable->getFullyQualifiedDisplayName();
|
||||
} else {
|
||||
$function = $callable->getDisplayName();
|
||||
}
|
||||
|
||||
$function = $this->renderer->escape($function);
|
||||
|
||||
if (null !== ($url = $callable->getPhpDocUrl())) {
|
||||
$function = '<a href="'.$url.'" target=_blank>'.$function.'</a>';
|
||||
}
|
||||
|
||||
$header .= $function;
|
||||
}
|
||||
|
||||
$children = $this->renderer->renderChildren($v);
|
||||
$header = $this->renderer->renderHeaderWrapper($v->getContext(), (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\Value\AbstractValue;
|
||||
|
||||
interface ValuePluginInterface extends PluginInterface
|
||||
{
|
||||
public function renderValue(AbstractValue $v): ?string;
|
||||
}
|
||||
+623
@@ -0,0 +1,623 @@
|
||||
<?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\Renderer\Rich\TabPluginInterface;
|
||||
use Kint\Renderer\Rich\ValuePluginInterface;
|
||||
use Kint\Utils;
|
||||
use Kint\Value\AbstractValue;
|
||||
use Kint\Value\Context\ClassDeclaredContext;
|
||||
use Kint\Value\Context\ContextInterface;
|
||||
use Kint\Value\Context\PropertyContext;
|
||||
use Kint\Value\InstanceValue;
|
||||
use Kint\Value\Representation;
|
||||
use Kint\Value\Representation\ContainerRepresentation;
|
||||
use Kint\Value\Representation\RepresentationInterface;
|
||||
use Kint\Value\Representation\StringRepresentation;
|
||||
use Kint\Value\Representation\ValueRepresentation;
|
||||
use Kint\Value\StringValue;
|
||||
|
||||
/**
|
||||
* @psalm-import-type Encoding from StringValue
|
||||
*/
|
||||
class RichRenderer extends AbstractRenderer
|
||||
{
|
||||
use AssetRendererTrait;
|
||||
|
||||
/**
|
||||
* RichRenderer value plugins should implement ValuePluginInterface.
|
||||
*
|
||||
* @psalm-var class-string<ValuePluginInterface>[]
|
||||
*/
|
||||
public static array $value_plugins = [
|
||||
'array_limit' => Rich\LockPlugin::class,
|
||||
'blacklist' => Rich\LockPlugin::class,
|
||||
'callable' => Rich\CallablePlugin::class,
|
||||
'color' => Rich\ColorPlugin::class,
|
||||
'depth_limit' => Rich\LockPlugin::class,
|
||||
'recursion' => Rich\LockPlugin::class,
|
||||
'trace_frame' => Rich\TraceFramePlugin::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* RichRenderer tab plugins should implement TabPluginInterface.
|
||||
*
|
||||
* @psalm-var array<string, class-string<TabPluginInterface>>
|
||||
*/
|
||||
public static array $tab_plugins = [
|
||||
'binary' => Rich\BinaryPlugin::class,
|
||||
'callable' => Rich\CallableDefinitionPlugin::class,
|
||||
'color' => Rich\ColorPlugin::class,
|
||||
'microtime' => Rich\MicrotimePlugin::class,
|
||||
'profiling' => Rich\ProfilePlugin::class,
|
||||
'source' => Rich\SourcePlugin::class,
|
||||
'table' => Rich\TablePlugin::class,
|
||||
];
|
||||
|
||||
public static array $pre_render_sources = [
|
||||
'script' => [
|
||||
[self::class, 'renderJs'],
|
||||
],
|
||||
'style' => [
|
||||
[self::class, 'renderCss'],
|
||||
],
|
||||
'raw' => [],
|
||||
];
|
||||
|
||||
/**
|
||||
* The maximum length of a string before it is truncated.
|
||||
*
|
||||
* Falsey to disable
|
||||
*/
|
||||
public static int $strlen_max = 80;
|
||||
|
||||
/**
|
||||
* Timestamp to print in footer in date() format.
|
||||
*/
|
||||
public static ?string $timestamp = null;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static bool $access_paths = true;
|
||||
|
||||
/**
|
||||
* 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%
|
||||
*/
|
||||
public static bool $escape_types = false;
|
||||
|
||||
/**
|
||||
* Move all dumps to a folder at the bottom of the body.
|
||||
*/
|
||||
public static bool $folder = false;
|
||||
|
||||
public static bool $needs_pre_render = true;
|
||||
public static bool $always_pre_render = false;
|
||||
|
||||
protected array $plugin_objs = [];
|
||||
protected bool $expand = false;
|
||||
protected bool $force_pre_render = false;
|
||||
protected bool $use_folder = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
self::$theme ??= 'original.css';
|
||||
$this->use_folder = self::$folder;
|
||||
$this->force_pre_render = self::$always_pre_render;
|
||||
}
|
||||
|
||||
public function setCallInfo(array $info): void
|
||||
{
|
||||
parent::setCallInfo($info);
|
||||
|
||||
if (\in_array('!', $info['modifiers'], true)) {
|
||||
$this->expand = true;
|
||||
$this->use_folder = false;
|
||||
}
|
||||
|
||||
if (\in_array('@', $info['modifiers'], true)) {
|
||||
$this->force_pre_render = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function setStatics(array $statics): void
|
||||
{
|
||||
parent::setStatics($statics);
|
||||
|
||||
if (!empty($statics['expanded'])) {
|
||||
$this->expand = true;
|
||||
}
|
||||
|
||||
if (!empty($statics['return'])) {
|
||||
$this->force_pre_render = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function shouldPreRender(): bool
|
||||
{
|
||||
return $this->force_pre_render || self::$needs_pre_render;
|
||||
}
|
||||
|
||||
public function render(AbstractValue $v): string
|
||||
{
|
||||
$render_spl_ids_stash = $this->render_spl_ids;
|
||||
|
||||
if ($this->render_spl_ids && $v->flags & AbstractValue::FLAG_GENERATED) {
|
||||
$this->render_spl_ids = false;
|
||||
}
|
||||
|
||||
if ($plugin = $this->getValuePlugin($v)) {
|
||||
$output = $plugin->renderValue($v);
|
||||
if (null !== $output && \strlen($output)) {
|
||||
if (!$this->render_spl_ids && $render_spl_ids_stash) {
|
||||
$this->render_spl_ids = true;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
$children = $this->renderChildren($v);
|
||||
$header = $this->renderHeaderWrapper($v->getContext(), (bool) \strlen($children), $this->renderHeader($v));
|
||||
|
||||
if (!$this->render_spl_ids && $render_spl_ids_stash) {
|
||||
$this->render_spl_ids = true;
|
||||
}
|
||||
|
||||
return '<dl>'.$header.$children.'</dl>';
|
||||
}
|
||||
|
||||
public function renderHeaderWrapper(ContextInterface $c, bool $has_children, string $contents): string
|
||||
{
|
||||
$out = '<dt';
|
||||
|
||||
if ($has_children) {
|
||||
$out .= ' class="kint-parent';
|
||||
|
||||
if ($this->expand) {
|
||||
$out .= ' kint-show';
|
||||
}
|
||||
|
||||
$out .= '"';
|
||||
}
|
||||
|
||||
$out .= '>';
|
||||
|
||||
if (self::$access_paths && $c->getDepth() > 0 && null !== ($ap = $c->getAccessPath())) {
|
||||
$out .= '<span class="kint-access-path-trigger" title="Show access path"></span>';
|
||||
}
|
||||
|
||||
if ($has_children) {
|
||||
if (0 === $c->getDepth()) {
|
||||
if (!$this->use_folder) {
|
||||
$out .= '<span class="kint-folder-trigger" title="Move to folder"></span>';
|
||||
}
|
||||
$out .= '<span class="kint-search-trigger" title="Show search box"></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(AbstractValue $v): string
|
||||
{
|
||||
$c = $v->getContext();
|
||||
|
||||
$output = '';
|
||||
|
||||
if ($c instanceof ClassDeclaredContext) {
|
||||
$output .= '<var>'.$c->getModifiers().'</var> ';
|
||||
}
|
||||
|
||||
$output .= '<dfn>'.$this->escape($v->getDisplayName()).'</dfn> ';
|
||||
|
||||
if ($c instanceof PropertyContext && null !== ($s = $c->getHooks())) {
|
||||
$output .= '<var>'.$this->escape($s).'</var> ';
|
||||
}
|
||||
|
||||
if (null !== ($s = $c->getOperator())) {
|
||||
$output .= $this->escape($s, 'ASCII').' ';
|
||||
}
|
||||
|
||||
$s = $v->getDisplayType();
|
||||
if (self::$escape_types) {
|
||||
$s = $this->escape($s);
|
||||
}
|
||||
|
||||
if ($c->isRef()) {
|
||||
$s = '&'.$s;
|
||||
}
|
||||
|
||||
$output .= '<var>'.$s.'</var>';
|
||||
|
||||
if ($v instanceof InstanceValue && $this->shouldRenderObjectIds()) {
|
||||
$output .= '#'.$v->getSplObjectId();
|
||||
}
|
||||
|
||||
$output .= ' ';
|
||||
|
||||
if (null !== ($s = $v->getDisplaySize())) {
|
||||
if (self::$escape_types) {
|
||||
$s = $this->escape($s);
|
||||
}
|
||||
$output .= '('.$s.') ';
|
||||
}
|
||||
|
||||
if (null !== ($s = $v->getDisplayValue())) {
|
||||
$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(AbstractValue $v): string
|
||||
{
|
||||
$contents = [];
|
||||
$tabs = [];
|
||||
|
||||
foreach ($v->getRepresentations() as $rep) {
|
||||
$result = $this->renderTab($v, $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->force_pre_render) {
|
||||
self::$needs_pre_render = false;
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '<div class="kint-rich';
|
||||
|
||||
if ($this->use_folder) {
|
||||
$output .= ' kint-file';
|
||||
}
|
||||
|
||||
$output .= '">';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function postRender(): string
|
||||
{
|
||||
if (!$this->show_trace) {
|
||||
return '</div>';
|
||||
}
|
||||
|
||||
$output = '<footer';
|
||||
|
||||
if ($this->expand) {
|
||||
$output .= ' class="kint-show"';
|
||||
}
|
||||
|
||||
$output .= '>';
|
||||
|
||||
if (!$this->use_folder) {
|
||||
$output .= '<span class="kint-folder-trigger" title="Move to folder">↧</span>';
|
||||
}
|
||||
|
||||
if (!empty($this->trace) && \count($this->trace) > 1) {
|
||||
$output .= '<nav></nav>';
|
||||
}
|
||||
|
||||
$output .= $this->calledFrom();
|
||||
|
||||
if (!empty($this->trace) && \count($this->trace) > 1) {
|
||||
$output .= '<ol>';
|
||||
foreach ($this->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 = Utils::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(Utils::shortenPath($file)).':'.$line;
|
||||
$ideLink = self::getFileLink($file, $line);
|
||||
|
||||
if (null === $ideLink) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
return '<a href="'.$this->escape($ideLink).'">'.$path.'</a>';
|
||||
}
|
||||
|
||||
protected function calledFrom(): string
|
||||
{
|
||||
$output = '';
|
||||
|
||||
if (isset($this->callee['file'])) {
|
||||
$output .= ' '.$this->ideLink(
|
||||
$this->callee['file'],
|
||||
$this->callee['line']
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
isset($this->callee['function']) &&
|
||||
(
|
||||
!empty($this->callee['class']) ||
|
||||
!\in_array(
|
||||
$this->callee['function'],
|
||||
['include', 'include_once', 'require', 'require_once'],
|
||||
true
|
||||
)
|
||||
)
|
||||
) {
|
||||
$output .= ' [';
|
||||
$output .= $this->callee['class'] ?? '';
|
||||
$output .= $this->callee['type'] ?? '';
|
||||
$output .= $this->callee['function'].'()]';
|
||||
}
|
||||
|
||||
if ('' !== $output) {
|
||||
$output = 'Called from'.$output;
|
||||
}
|
||||
|
||||
if (null !== self::$timestamp) {
|
||||
$output .= ' '.\date(self::$timestamp);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function renderTab(AbstractValue $v, RepresentationInterface $rep): string
|
||||
{
|
||||
if ($plugin = $this->getTabPlugin($rep)) {
|
||||
$output = $plugin->renderTab($rep, $v);
|
||||
if (null !== $output) {
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
if ($rep instanceof ValueRepresentation) {
|
||||
return $this->render($rep->getValue());
|
||||
}
|
||||
|
||||
if ($rep instanceof ContainerRepresentation) {
|
||||
$output = '';
|
||||
|
||||
foreach ($rep->getContents() as $obj) {
|
||||
$output .= $this->render($obj);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
if ($rep instanceof StringRepresentation) {
|
||||
// If we're dealing with the content representation
|
||||
if ($v instanceof StringValue && $rep->getValue() === $v->getValue()) {
|
||||
// Only show the contents if:
|
||||
if (\preg_match('/(:?[\\r\\n\\t\\f\\v]| {2})/', $rep->getValue())) {
|
||||
// We have unrepresentable whitespace (Without whitespace preservation)
|
||||
$show_contents = true;
|
||||
} elseif (self::$strlen_max && Utils::strlen($v->getDisplayValue()) > self::$strlen_max) {
|
||||
// We had to truncate getDisplayValue
|
||||
$show_contents = true;
|
||||
} else {
|
||||
$show_contents = false;
|
||||
}
|
||||
} else {
|
||||
$show_contents = true;
|
||||
}
|
||||
|
||||
if ($show_contents) {
|
||||
return '<pre>'.$this->escape($rep->getValue())."\n</pre>";
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function getValuePlugin(AbstractValue $v): ?ValuePluginInterface
|
||||
{
|
||||
$hint = $v->getHint();
|
||||
|
||||
if (null === $hint || !isset(self::$value_plugins[$hint])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$plugin = self::$value_plugins[$hint];
|
||||
|
||||
if (!\is_a($plugin, ValuePluginInterface::class, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($this->plugin_objs[$plugin])) {
|
||||
$this->plugin_objs[$plugin] = new $plugin($this);
|
||||
}
|
||||
|
||||
return $this->plugin_objs[$plugin];
|
||||
}
|
||||
|
||||
protected function getTabPlugin(RepresentationInterface $r): ?TabPluginInterface
|
||||
{
|
||||
$hint = $r->getHint();
|
||||
|
||||
if (null === $hint || !isset(self::$tab_plugins[$hint])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$plugin = self::$tab_plugins[$hint];
|
||||
|
||||
if (!\is_a($plugin, TabPluginInterface::class, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($this->plugin_objs[$plugin])) {
|
||||
$this->plugin_objs[$plugin] = new $plugin($this);
|
||||
}
|
||||
|
||||
return $this->plugin_objs[$plugin];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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\Value\AbstractValue;
|
||||
|
||||
abstract class AbstractPlugin implements PluginInterface
|
||||
{
|
||||
protected TextRenderer $renderer;
|
||||
|
||||
public function __construct(TextRenderer $r)
|
||||
{
|
||||
$this->renderer = $r;
|
||||
}
|
||||
|
||||
public function renderLockedHeader(AbstractValue $v, ?string $content = null): string
|
||||
{
|
||||
$out = '';
|
||||
|
||||
if (0 === $v->getContext()->getDepth()) {
|
||||
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($v)).PHP_EOL;
|
||||
}
|
||||
|
||||
$out .= $this->renderer->renderHeader($v);
|
||||
|
||||
if (null !== $content) {
|
||||
$out .= ' '.$this->renderer->colorValue($content);
|
||||
}
|
||||
|
||||
$out .= PHP_EOL;
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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\Value\AbstractValue;
|
||||
|
||||
class LockPlugin extends AbstractPlugin
|
||||
{
|
||||
public function render(AbstractValue $v): ?string
|
||||
{
|
||||
switch ($v->getHint()) {
|
||||
case 'blacklist':
|
||||
return $this->renderLockedHeader($v, 'BLACKLISTED');
|
||||
case 'recursion':
|
||||
return $this->renderLockedHeader($v, 'RECURSION');
|
||||
case 'depth_limit':
|
||||
return $this->renderLockedHeader($v, 'DEPTH LIMIT');
|
||||
case 'array_limit':
|
||||
return $this->renderLockedHeader($v, 'ARRAY LIMIT');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?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\TextRenderer;
|
||||
use Kint\Utils;
|
||||
use Kint\Value\AbstractValue;
|
||||
use Kint\Value\Representation\MicrotimeRepresentation;
|
||||
|
||||
class MicrotimePlugin extends AbstractPlugin
|
||||
{
|
||||
protected bool $useJs = false;
|
||||
|
||||
public function __construct(TextRenderer $r)
|
||||
{
|
||||
parent::__construct($r);
|
||||
|
||||
if ($this->renderer instanceof PlainRenderer) {
|
||||
$this->useJs = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function render(AbstractValue $v): ?string
|
||||
{
|
||||
$r = $v->getRepresentation('microtime');
|
||||
|
||||
if (!$r instanceof MicrotimeRepresentation || !($dt = $r->getDateTime())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$c = $v->getContext();
|
||||
|
||||
$out = '';
|
||||
|
||||
if (0 === $c->getDepth()) {
|
||||
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($v)).PHP_EOL;
|
||||
}
|
||||
|
||||
$out .= $this->renderer->renderHeader($v);
|
||||
$out .= $this->renderer->renderChildren($v).PHP_EOL;
|
||||
|
||||
$indent = \str_repeat(' ', ($c->getDepth() + 1) * $this->renderer->indent_width);
|
||||
|
||||
if ($this->useJs) {
|
||||
$out .= '<span data-kint-microtime-group="'.$r->getGroup().'">';
|
||||
}
|
||||
|
||||
$out .= $indent.$this->renderer->colorType('TIME:').' ';
|
||||
$out .= $this->renderer->colorValue($dt->format('Y-m-d H:i:s.u')).PHP_EOL;
|
||||
|
||||
if (null !== ($lap = $r->getLapTime())) {
|
||||
$out .= $indent.$this->renderer->colorType('SINCE LAST CALL:').' ';
|
||||
|
||||
$lap = \round($lap, 4);
|
||||
|
||||
if ($this->useJs) {
|
||||
$lap = '<span class="kint-microtime-lap">'.$lap.'</span>';
|
||||
}
|
||||
|
||||
$out .= $this->renderer->colorValue($lap.'s').'.'.PHP_EOL;
|
||||
}
|
||||
if (null !== ($total = $r->getTotalTime())) {
|
||||
$out .= $indent.$this->renderer->colorType('SINCE START:').' ';
|
||||
$out .= $this->renderer->colorValue(\round($total, 4).'s').'.'.PHP_EOL;
|
||||
}
|
||||
if (null !== ($avg = $r->getAverageTime())) {
|
||||
$out .= $indent.$this->renderer->colorType('AVERAGE DURATION:').' ';
|
||||
|
||||
$avg = \round($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->getMemoryUsage());
|
||||
$mem = $r->getMemoryUsage().' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
|
||||
$bytes = Utils::getHumanReadableBytes($r->getMemoryUsageReal());
|
||||
$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->getMemoryPeakUsage());
|
||||
$mem = $r->getMemoryPeakUsage().' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
|
||||
$bytes = Utils::getHumanReadableBytes($r->getMemoryPeakUsageReal());
|
||||
$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;
|
||||
}
|
||||
}
|
||||
@@ -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\Value\AbstractValue;
|
||||
|
||||
interface PluginInterface
|
||||
{
|
||||
public function __construct(TextRenderer $r);
|
||||
|
||||
public function render(AbstractValue $v): ?string;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Kint\Value\Representation\SplFileInfoRepresentation;
|
||||
|
||||
class SplFileInfoPlugin extends AbstractPlugin
|
||||
{
|
||||
public function render(AbstractValue $v): ?string
|
||||
{
|
||||
$r = $v->getRepresentation('splfileinfo');
|
||||
|
||||
if (!$r instanceof SplFileInfoRepresentation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$out = '';
|
||||
|
||||
$c = $v->getContext();
|
||||
|
||||
if (0 === $c->getDepth()) {
|
||||
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($v)).PHP_EOL;
|
||||
}
|
||||
|
||||
$out .= $this->renderer->renderHeader($v);
|
||||
if (null !== $v->getDisplayValue()) {
|
||||
$out .= ' =>';
|
||||
}
|
||||
$out .= ' '.$this->renderer->colorValue($this->renderer->escape($r->getValue())).PHP_EOL;
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?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\Value\AbstractValue;
|
||||
use Kint\Value\MethodValue;
|
||||
use Kint\Value\Representation\SourceRepresentation;
|
||||
use Kint\Value\TraceFrameValue;
|
||||
use Kint\Value\TraceValue;
|
||||
|
||||
class TracePlugin extends AbstractPlugin
|
||||
{
|
||||
public function render(AbstractValue $v): ?string
|
||||
{
|
||||
if (!$v instanceof TraceValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$c = $v->getContext();
|
||||
|
||||
$out = '';
|
||||
|
||||
if (0 === $c->getDepth()) {
|
||||
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($v)).PHP_EOL;
|
||||
}
|
||||
|
||||
$out .= $this->renderer->renderHeader($v).':'.PHP_EOL;
|
||||
|
||||
$indent = \str_repeat(' ', ($c->getDepth() + 1) * $this->renderer->indent_width);
|
||||
|
||||
$i = 1;
|
||||
foreach ($v->getContents() as $frame) {
|
||||
if (!$frame instanceof TraceFrameValue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$framedesc = $indent.\str_pad($i.': ', 4, ' ');
|
||||
|
||||
if (null !== ($file = $frame->getFile()) && null !== ($line = $frame->getLine())) {
|
||||
$framedesc .= $this->renderer->ideLink($file, $line).PHP_EOL;
|
||||
} else {
|
||||
$framedesc .= 'PHP internal call'.PHP_EOL;
|
||||
}
|
||||
|
||||
if ($callable = $frame->getCallable()) {
|
||||
$framedesc .= $indent.' ';
|
||||
|
||||
if ($callable instanceof MethodValue) {
|
||||
$framedesc .= $this->renderer->escape($callable->getContext()->owner_class.$callable->getContext()->getOperator());
|
||||
}
|
||||
|
||||
$framedesc .= $this->renderer->escape($callable->getDisplayName());
|
||||
}
|
||||
|
||||
$out .= $this->renderer->colorType($framedesc).PHP_EOL.PHP_EOL;
|
||||
|
||||
$source = $frame->getRepresentation('source');
|
||||
|
||||
if ($source instanceof SourceRepresentation) {
|
||||
$line_wanted = $source->getLine();
|
||||
$source = $source->getSourceLines();
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
+400
@@ -0,0 +1,400 @@
|
||||
<?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\Parser;
|
||||
use Kint\Parser\PluginInterface as ParserPluginInterface;
|
||||
use Kint\Renderer\Text\PluginInterface;
|
||||
use Kint\Utils;
|
||||
use Kint\Value\AbstractValue;
|
||||
use Kint\Value\ArrayValue;
|
||||
use Kint\Value\Context\ArrayContext;
|
||||
use Kint\Value\Context\ClassDeclaredContext;
|
||||
use Kint\Value\Context\PropertyContext;
|
||||
use Kint\Value\InstanceValue;
|
||||
use Kint\Value\StringValue;
|
||||
|
||||
/**
|
||||
* @psalm-import-type Encoding from StringValue
|
||||
*/
|
||||
class TextRenderer extends AbstractRenderer
|
||||
{
|
||||
/**
|
||||
* TextRenderer plugins should implement PluginInterface.
|
||||
*
|
||||
* @psalm-var class-string<PluginInterface>[]
|
||||
*/
|
||||
public static array $plugins = [
|
||||
'array_limit' => Text\LockPlugin::class,
|
||||
'blacklist' => Text\LockPlugin::class,
|
||||
'depth_limit' => Text\LockPlugin::class,
|
||||
'splfileinfo' => Text\SplFileInfoPlugin::class,
|
||||
'microtime' => Text\MicrotimePlugin::class,
|
||||
'recursion' => Text\LockPlugin::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<ParserPluginInterface>[]
|
||||
*/
|
||||
public static array $parser_plugin_whitelist = [
|
||||
Parser\ArrayLimitPlugin::class,
|
||||
Parser\ArrayObjectPlugin::class,
|
||||
Parser\BlacklistPlugin::class,
|
||||
Parser\ClosurePlugin::class,
|
||||
Parser\DateTimePlugin::class,
|
||||
Parser\DomPlugin::class,
|
||||
Parser\EnumPlugin::class,
|
||||
Parser\IteratorPlugin::class,
|
||||
Parser\MicrotimePlugin::class,
|
||||
Parser\MysqliPlugin::class,
|
||||
Parser\SimpleXMLElementPlugin::class,
|
||||
Parser\SplFileInfoPlugin::class,
|
||||
Parser\StreamPlugin::class,
|
||||
Parser\TracePlugin::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The maximum length of a string before it is truncated.
|
||||
*
|
||||
* Falsey to disable
|
||||
*/
|
||||
public static int $strlen_max = 0;
|
||||
|
||||
/**
|
||||
* Timestamp to print in footer in date() format.
|
||||
*/
|
||||
public static ?string $timestamp = null;
|
||||
|
||||
/**
|
||||
* The default width of the terminal for headers.
|
||||
*/
|
||||
public static int $default_width = 80;
|
||||
|
||||
/**
|
||||
* Indentation width.
|
||||
*/
|
||||
public static int $default_indent = 4;
|
||||
|
||||
/**
|
||||
* Decorate the header and footer.
|
||||
*/
|
||||
public static bool $decorations = true;
|
||||
|
||||
public int $header_width = 80;
|
||||
public int $indent_width = 4;
|
||||
|
||||
protected array $plugin_objs = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->header_width = self::$default_width;
|
||||
$this->indent_width = self::$default_indent;
|
||||
}
|
||||
|
||||
public function render(AbstractValue $v): string
|
||||
{
|
||||
$render_spl_ids_stash = $this->render_spl_ids;
|
||||
|
||||
if ($this->render_spl_ids && ($v->flags & AbstractValue::FLAG_GENERATED)) {
|
||||
$this->render_spl_ids = false;
|
||||
}
|
||||
|
||||
if ($plugin = $this->getPlugin($v)) {
|
||||
$output = $plugin->render($v);
|
||||
if (null !== $output && \strlen($output)) {
|
||||
if (!$this->render_spl_ids && $render_spl_ids_stash) {
|
||||
$this->render_spl_ids = true;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
$out = '';
|
||||
|
||||
$c = $v->getContext();
|
||||
|
||||
if (0 === $c->getDepth()) {
|
||||
$out .= $this->colorTitle($this->renderTitle($v)).PHP_EOL;
|
||||
}
|
||||
|
||||
$out .= $header = $this->renderHeader($v);
|
||||
$out .= $this->renderChildren($v);
|
||||
|
||||
if (\strlen($header)) {
|
||||
$out .= PHP_EOL;
|
||||
}
|
||||
|
||||
if (!$this->render_spl_ids && $render_spl_ids_stash) {
|
||||
$this->render_spl_ids = true;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
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(AbstractValue $v): string
|
||||
{
|
||||
if (self::$decorations) {
|
||||
return $this->boxText($v->getDisplayName(), $this->header_width);
|
||||
}
|
||||
|
||||
return Utils::truncateString($v->getDisplayName(), $this->header_width);
|
||||
}
|
||||
|
||||
public function renderHeader(AbstractValue $v): string
|
||||
{
|
||||
$output = [];
|
||||
|
||||
$c = $v->getContext();
|
||||
|
||||
if ($c->getDepth() > 0) {
|
||||
if ($c instanceof ClassDeclaredContext) {
|
||||
$output[] = $this->colorType($c->getModifiers());
|
||||
}
|
||||
|
||||
if ($c instanceof ArrayContext) {
|
||||
$output[] = $this->escape(\var_export($c->getName(), true));
|
||||
} else {
|
||||
$output[] = $this->escape((string) $c->getName());
|
||||
}
|
||||
|
||||
if ($c instanceof PropertyContext && null !== ($s = $c->getHooks())) {
|
||||
$output[] = $this->colorType($this->escape($s));
|
||||
}
|
||||
|
||||
if (null !== ($s = $c->getOperator())) {
|
||||
$output[] = $this->escape($s);
|
||||
}
|
||||
}
|
||||
|
||||
$s = $v->getDisplayType();
|
||||
if ($c->isRef()) {
|
||||
$s = '&'.$s;
|
||||
}
|
||||
|
||||
$s = $this->colorType($this->escape($s));
|
||||
|
||||
if ($v instanceof InstanceValue && $this->shouldRenderObjectIds()) {
|
||||
$s .= '#'.$v->getSplObjectId();
|
||||
}
|
||||
|
||||
$output[] = $s;
|
||||
|
||||
if (null !== ($s = $v->getDisplaySize())) {
|
||||
$output[] = '('.$this->escape($s).')';
|
||||
}
|
||||
|
||||
if (null !== ($s = $v->getDisplayValue())) {
|
||||
if (self::$strlen_max) {
|
||||
$s = Utils::truncateString($s, self::$strlen_max);
|
||||
}
|
||||
$output[] = $this->colorValue($this->escape($s));
|
||||
}
|
||||
|
||||
return \str_repeat(' ', $c->getDepth() * $this->indent_width).\implode(' ', $output);
|
||||
}
|
||||
|
||||
public function renderChildren(AbstractValue $v): string
|
||||
{
|
||||
$children = $v->getDisplayChildren();
|
||||
|
||||
if (!$children) {
|
||||
if ($v instanceof ArrayValue) {
|
||||
return ' []';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($v instanceof ArrayValue) {
|
||||
$output = ' [';
|
||||
} elseif ($v instanceof InstanceValue) {
|
||||
$output = ' (';
|
||||
} else {
|
||||
$output = '';
|
||||
}
|
||||
|
||||
$output .= PHP_EOL;
|
||||
foreach ($children as $child) {
|
||||
$output .= $this->render($child);
|
||||
}
|
||||
|
||||
$indent = \str_repeat(' ', $v->getContext()->getDepth() * $this->indent_width);
|
||||
|
||||
if ($v instanceof ArrayValue) {
|
||||
$output .= $indent.']';
|
||||
} elseif ($v instanceof InstanceValue) {
|
||||
$output .= $indent.')';
|
||||
}
|
||||
|
||||
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(Utils::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->callee['file'])) {
|
||||
$output .= 'Called from '.$this->ideLink(
|
||||
$this->callee['file'],
|
||||
$this->callee['line']
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
isset($this->callee['function']) &&
|
||||
(
|
||||
!empty($this->callee['class']) ||
|
||||
!\in_array(
|
||||
$this->callee['function'],
|
||||
['include', 'include_once', 'require', 'require_once'],
|
||||
true
|
||||
)
|
||||
)
|
||||
) {
|
||||
$output .= ' [';
|
||||
$output .= $this->callee['class'] ?? '';
|
||||
$output .= $this->callee['type'] ?? '';
|
||||
$output .= $this->callee['function'].'()]';
|
||||
}
|
||||
|
||||
if (null !== self::$timestamp) {
|
||||
if (\strlen($output)) {
|
||||
$output .= ' ';
|
||||
}
|
||||
$output .= \date(self::$timestamp);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function getPlugin(AbstractValue $v): ?PluginInterface
|
||||
{
|
||||
$hint = $v->getHint();
|
||||
|
||||
if (null === $hint || !isset(self::$plugins[$hint])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$plugin = self::$plugins[$hint];
|
||||
|
||||
if (!\is_a($plugin, PluginInterface::class, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($this->plugin_objs[$plugin])) {
|
||||
$this->plugin_objs[$plugin] = new $plugin($this);
|
||||
}
|
||||
|
||||
return $this->plugin_objs[$plugin];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user