Skip to content

Commit

Permalink
SimpleXML fixes
Browse files Browse the repository at this point in the history
* Don't allow expanding strings that are already fully shown in getValueShort
* Don't add empty attribute representations
* Bugfix value representations
  • Loading branch information
jnvsor committed Nov 11, 2022
1 parent b5841ee commit 38a7859
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
Binary file modified build/kint.phar
Binary file not shown.
8 changes: 5 additions & 3 deletions src/Parser/SimpleXMLElementPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/Renderer/Rich/SimpleXMLElementPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Jonathan Vollebregt ([email protected]), Rokas Šleinius ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

namespace Kint\Renderer\Rich;

use Kint\Zval\BlobValue;
use Kint\Zval\SimpleXMLElementValue;
use Kint\Zval\Value;

class SimpleXMLElementPlugin extends AbstractPlugin implements ValuePluginInterface
{
public function renderValue(Value $o): ?string
{
if (!($o instanceof SimpleXMLElementValue)) {
return null;
}

if (!$o->isStringValue() || !empty($o->getRepresentation('attributes')->contents)) {
return null;
}

$b = new BlobValue();
$b->transplant($o);
$b->type = 'string';

$children = $this->renderer->renderChildren($b);
$header = $this->renderer->renderHeader($o);
$header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header);

return '<dl>'.$header.$children.'</dl>';
}
}
1 change: 1 addition & 0 deletions src/Renderer/RichRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

Expand Down
5 changes: 5 additions & 0 deletions src/Zval/SimpleXMLElementValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 38a7859

Please sign in to comment.