Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HtmlDumper.php

function HtmlDumper::style

Overrides CliDumper::style

1 call to HtmlDumper::style()
HtmlDumper::dumpString in vendor/symfony/var-dumper/Dumper/HtmlDumper.php
Dumps a string.

File

vendor/symfony/var-dumper/Dumper/HtmlDumper.php, line 826

Class

HtmlDumper
HtmlDumper dumps variables as HTML.

Namespace

Symfony\Component\VarDumper\Dumper

Code

protected function style(string $style, string $value, array $attr = []) : string {
    if ('' === $value && ('label' !== $style || !isset($attr['file']) && !isset($attr['href']))) {
        return '';
    }
    $v = esc($value);
    if ('ref' === $style) {
        if (empty($attr['count'])) {
            return \sprintf('<a class=sf-dump-ref>%s</a>', $v);
        }
        $r = ('#' !== $v[0] ? 1 - ('@' !== $v[0]) : 2) . substr($value, 1);
        return \sprintf('<a class=sf-dump-ref href=#%s-ref%s title="%d occurrences">%s</a>', $this->dumpId, $r, 1 + $attr['count'], $v);
    }
    if ('const' === $style && isset($attr['value'])) {
        $style .= \sprintf(' title="%s"', esc(\is_scalar($attr['value']) ? $attr['value'] : json_encode($attr['value'])));
    }
    elseif ('public' === $style) {
        $style .= \sprintf(' title="%s"', empty($attr['dynamic']) ? 'Public property' : 'Runtime added dynamic property');
    }
    elseif ('str' === $style && 1 < $attr['length']) {
        $style .= \sprintf(' title="%d%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : '');
    }
    elseif ('note' === $style && 0 < ($attr['depth'] ?? 0) && false !== ($c = strrpos($value, '\\'))) {
        $style .= ' title=""';
        $attr += [
            'ellipsis' => \strlen($value) - $c,
            'ellipsis-type' => 'note',
            'ellipsis-tail' => 1,
        ];
    }
    elseif ('protected' === $style) {
        $style .= ' title="Protected property"';
    }
    elseif ('meta' === $style && isset($attr['title'])) {
        $style .= \sprintf(' title="%s"', esc($this->utf8Encode($attr['title'])));
    }
    elseif ('private' === $style) {
        $style .= \sprintf(' title="Private property defined in class:&#10;`%s`"', esc($this->utf8Encode($attr['class'])));
    }
    if (isset($attr['ellipsis'])) {
        $class = 'sf-dump-ellipsis';
        if (isset($attr['ellipsis-type'])) {
            $class = \sprintf('"%s sf-dump-ellipsis-%s"', $class, $attr['ellipsis-type']);
        }
        $label = esc(substr($value, -$attr['ellipsis']));
        $style = str_replace(' title="', " title=\"{$v}\n", $style);
        $v = \sprintf('<span class=%s>%s</span>', $class, substr($v, 0, -\strlen($label)));
        if (!empty($attr['ellipsis-tail'])) {
            $tail = \strlen(esc(substr($value, -$attr['ellipsis'], $attr['ellipsis-tail'])));
            $v .= \sprintf('<span class=%s>%s</span>%s', $class, substr($label, 0, $tail), substr($label, $tail));
        }
        else {
            $v .= $label;
        }
    }
    $map = static::$controlCharsMap;
    $v = "<span class=sf-dump-{$style}>" . preg_replace_callback(static::$controlCharsRx, function ($c) use ($map) {
        $s = $b = '<span class="sf-dump-default';
        $c = $c[$i = 0];
        if ($ns = "\r" === $c[$i] || "\n" === $c[$i]) {
            $s .= ' sf-dump-ns';
        }
        $s .= '">';
        do {
            if (("\r" === $c[$i] || "\n" === $c[$i]) !== $ns) {
                $s .= '</span>' . $b;
                if ($ns = !$ns) {
                    $s .= ' sf-dump-ns';
                }
                $s .= '">';
            }
            $s .= $map[$c[$i]] ?? \sprintf('\\x%02X', \ord($c[$i]));
        } while (isset($c[++$i]));
        return $s . '</span>';
    }, $v) . '</span>';
    if (!($attr['binary'] ?? false)) {
        $v = preg_replace_callback(static::$unicodeCharsRx, function ($c) {
            return '<span class=sf-dump-default>\\u{' . strtoupper(dechex(mb_ord($c[0]))) . '}</span>';
        }, $v);
    }
    if (isset($attr['file']) && ($href = $this->getSourceLink($attr['file'], $attr['line'] ?? 0))) {
        $attr['href'] = $href;
    }
    if (isset($attr['href'])) {
        if ('label' === $style) {
            $v .= '^';
        }
        $target = isset($attr['file']) ? '' : ' target="_blank"';
        $v = \sprintf('<a href="%s"%s rel="noopener noreferrer">%s</a>', esc($this->utf8Encode($attr['href'])), $target, $v);
    }
    if (isset($attr['lang'])) {
        $v = \sprintf('<code class="%s">%s</code>', esc($attr['lang']), $v);
    }
    if ('label' === $style) {
        $v .= ' ';
    }
    if ($attr['virtual'] ?? false) {
        $v = '<span class=sf-dump-virtual>' . $v . '</span>';
    }
    return $v;
}
RSS feed
Powered by Drupal