From 38a7859e96557345f2f7a7e73e49bf7034a2d5dd Mon Sep 17 00:00:00 2001 From: Jonathan Vollebregt Date: Fri, 11 Nov 2022 20:23:28 +0100 Subject: [PATCH] SimpleXML fixes * Don't allow expanding strings that are already fully shown in getValueShort * Don't add empty attribute representations * Bugfix value representations --- build/kint.phar | Bin 431578 -> 433924 bytes src/Parser/SimpleXMLElementPlugin.php | 8 ++- src/Renderer/Rich/SimpleXMLElementPlugin.php | 56 +++++++++++++++++++ src/Renderer/RichRenderer.php | 1 + src/Zval/SimpleXMLElementValue.php | 5 ++ 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/Renderer/Rich/SimpleXMLElementPlugin.php diff --git a/build/kint.phar b/build/kint.phar index ad12ad5fcb7e3789d804193c3764c4ce48f0e5ce..d6c1843a9547e89ed6cc9f8522ef5e6443384073 100644 GIT binary patch delta 554 zcmcb$TB>EA)CLw-RwW4rhK$Xete@Eh8f6(68usbPfaqHt?3SIENo1=cGJ%;V3C+E{*Os~`h6iL+3ioiGOgrd z*R?B4%qdNs+QV`86v_7#)v^oFO* znS2^5`3jkN#U+V($*K8i(-ke)#HKg7vq?;Uz{|)r{lG<5{^%ar%dk%+icW)91`! zk_A#1^_ZoFlXUG$DhpB-Y!%dt!KSHOPmjC7Y|fmdX+3@7W@h2(^ItH_P8a{cEH*vi zIsa99rsVqN$)_7noYl)yWife&J?iScnOC%fO+bhpA_}5k7F+Z-FO_azD$TfksWemEt?8Zrn8eux^`uWIi;!74=^!{P2TXErCorDdAk4; zOQq8E2V%_n(+lo0@=o{BWfq&BaFm&S`!^kyOLpztIV{_`b68uhZhz~@c0R`ALz2&e z_MK95Q*Q6wkzs!8pq&ZZ@x@$+C4ccnNW7C+r*`mnhf(Jjy^CjqKgeB6d9%4qZ-dc^ YrIrW$pI&|(B=_hC3j+g#yOXaI0LqAGJpcdz diff --git a/src/Parser/SimpleXMLElementPlugin.php b/src/Parser/SimpleXMLElementPlugin.php index a4ad6d623..db6f9b9c1 100644 --- a/src/Parser/SimpleXMLElementPlugin.php +++ b/src/Parser/SimpleXMLElementPlugin.php @@ -125,7 +125,9 @@ public function parse(&$var, Value &$o, int $trigger): void } } - $x->addRepresentation($a, 0); + if ($a->contents) { + $x->addRepresentation($a, 0); + } // Children $c = new Representation('Children'); @@ -195,14 +197,14 @@ public function parse(&$var, Value &$o, int $trigger): void $s = $this->parser->parse($value, $base_obj); $srep = $s->getRepresentation('contents'); - $svalrep = $s->value && 'contents' == $s->value->getName() ? $s : null; + $svalrep = $s->value && 'contents' == $s->value->getName() ? $s->value : null; if ($srep || $svalrep) { $x->setIsStringValue(true); $x->value = $srep ?: $svalrep; if ($srep) { - $x->replaceRepresentation($x->value, 0); + $x->replaceRepresentation($srep, 0); } } diff --git a/src/Renderer/Rich/SimpleXMLElementPlugin.php b/src/Renderer/Rich/SimpleXMLElementPlugin.php new file mode 100644 index 000000000..87d987079 --- /dev/null +++ b/src/Renderer/Rich/SimpleXMLElementPlugin.php @@ -0,0 +1,56 @@ +isStringValue() || !empty($o->getRepresentation('attributes')->contents)) { + return null; + } + + $b = new BlobValue(); + $b->transplant($o); + $b->type = 'string'; + + $children = $this->renderer->renderChildren($b); + $header = $this->renderer->renderHeader($o); + $header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header); + + return '
'.$header.$children.'
'; + } +} diff --git a/src/Renderer/RichRenderer.php b/src/Renderer/RichRenderer.php index 4ef045f46..ecedb40b5 100644 --- a/src/Renderer/RichRenderer.php +++ b/src/Renderer/RichRenderer.php @@ -56,6 +56,7 @@ class RichRenderer extends AbstractRenderer 'color' => Rich\ColorPlugin::class, 'depth_limit' => Rich\DepthLimitPlugin::class, 'recursion' => Rich\RecursionPlugin::class, + 'simplexml_element' => Rich\SimpleXMLElementPlugin::class, 'trace_frame' => Rich\TraceFramePlugin::class, ]; diff --git a/src/Zval/SimpleXMLElementValue.php b/src/Zval/SimpleXMLElementValue.php index 97d778ee3..0f152230e 100644 --- a/src/Zval/SimpleXMLElementValue.php +++ b/src/Zval/SimpleXMLElementValue.php @@ -33,6 +33,11 @@ class SimpleXMLElementValue extends InstanceValue protected $is_string_value = false; + public function isStringValue(): bool + { + return $this->is_string_value; + } + public function setIsStringValue(bool $is_string_value): void { $this->is_string_value = $is_string_value;