Skip to content

Commit

Permalink
Iterator Primary
Browse files Browse the repository at this point in the history
This basically replaces the object value with the iterator
representation in text dumps, so it's to be used when text
rendering something where the iterator contents are more
useful than the properties like NodeList or SplObjectStorage.

Due to how it's implemented we no longer need the
SplObjectStoragePlugin at all
  • Loading branch information
jnvsor committed Aug 21, 2024
1 parent 6865e61 commit 14eeb47
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
Binary file modified build/kint.phar
Binary file not shown.
1 change: 0 additions & 1 deletion src/Kint.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ class Kint implements FacadeInterface
\Kint\Parser\MicrotimePlugin::class,
\Kint\Parser\SimpleXMLElementPlugin::class,
\Kint\Parser\SplFileInfoPlugin::class,
\Kint\Parser\SplObjectStoragePlugin::class,
\Kint\Parser\StreamPlugin::class,
\Kint\Parser\TablePlugin::class,
\Kint\Parser\ThrowablePlugin::class,
Expand Down
2 changes: 2 additions & 0 deletions src/Parser/IteratorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public function parse(&$var, Value &$o, int $trigger): void
$primary = \reset($primary);
if ($primary && $primary === $o->value && [] === $primary->contents) {
$o->addRepresentation($r, 0);
$o->hints[] = 'iterator_primary';
$o->size = \count($data) ?: null;
} else {
$o->addRepresentation($r);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,18 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

namespace Kint\Parser;
namespace Kint\Renderer\Text;

use Kint\Zval\Value;
use SplObjectStorage;

class SplObjectStoragePlugin extends AbstractPlugin
class IteratorPrimaryPlugin extends AbstractPlugin
{
public function getTypes(): array
public function render(Value $o): string
{
return ['object'];
}

public function getTriggers(): int
{
return Parser::TRIGGER_COMPLETE;
}

public function parse(&$var, Value &$o, int $trigger): void
{
if (!$var instanceof SplObjectStorage || !($r = $o->getRepresentation('iterator'))) {
return;
}
$out = clone $o;
$out->hints = \array_diff($out->hints, ['iterator_primary']);
$out->value = $o->getRepresentation('iterator') ?? $out->value;

$r = $o->getRepresentation('iterator');
if ($r) {
$o->size = !\is_array($r->contents) ? null : \count($r->contents);
}
return $this->renderer->render($out);
}
}
2 changes: 2 additions & 0 deletions src/Renderer/TextRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TextRenderer extends AbstractRenderer
'blacklist' => Text\BlacklistPlugin::class,
'depth_limit' => Text\DepthLimitPlugin::class,
'enum' => Text\EnumPlugin::class,
'iterator_primary' => Text\IteratorPrimaryPlugin::class,
'microtime' => Text\MicrotimePlugin::class,
'recursion' => Text\RecursionPlugin::class,
'trace' => Text\TracePlugin::class,
Expand All @@ -67,6 +68,7 @@ class TextRenderer extends AbstractRenderer
Parser\ArrayObjectPlugin::class,
Parser\BlacklistPlugin::class,
Parser\EnumPlugin::class,
Parser\IteratorPlugin::class,
Parser\MicrotimePlugin::class,
Parser\StreamPlugin::class,
Parser\TracePlugin::class,
Expand Down

0 comments on commit 14eeb47

Please sign in to comment.