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

Breadcrumb

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

function CliDumper::dumpString

Overrides DumperInterface::dumpString

2 calls to CliDumper::dumpString()
HtmlDumper::dumpString in vendor/symfony/var-dumper/Dumper/HtmlDumper.php
Dumps a string.
HtmlDumper::dumpString in vendor/symfony/var-dumper/Dumper/HtmlDumper.php
Dumps a string.
1 method overrides CliDumper::dumpString()
HtmlDumper::dumpString in vendor/symfony/var-dumper/Dumper/HtmlDumper.php
Dumps a string.

File

vendor/symfony/var-dumper/Dumper/CliDumper.php, line 187

Class

CliDumper
CliDumper dumps variables for command line output.

Namespace

Symfony\Component\VarDumper\Dumper

Code

public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut) : void {
    $this->dumpKey($cursor);
    $this->collapseNextHash = $this->expandNextHash = false;
    $attr = $cursor->attr;
    if ($bin) {
        $str = $this->utf8Encode($str);
    }
    if ('' === $str) {
        $this->line .= '""';
        if ($cut) {
            $this->line .= '…' . $cut;
        }
        $this->endValue($cursor);
    }
    else {
        $attr += [
            'length' => 0 <= $cut ? mb_strlen($str, 'UTF-8') + $cut : 0,
            'binary' => $bin,
        ];
        $str = $bin && str_contains($str, "\x00") ? [
            $str,
        ] : explode("\n", $str);
        if (isset($str[1]) && !isset($str[2]) && !isset($str[1][0])) {
            unset($str[1]);
            $str[0] .= "\n";
        }
        $m = \count($str) - 1;
        $i = $lineCut = 0;
        if (self::DUMP_STRING_LENGTH & $this->flags) {
            $this->line .= '(' . $attr['length'] . ') ';
        }
        if ($bin) {
            $this->line .= 'b';
        }
        if ($m) {
            $this->line .= '"""';
            $this->dumpLine($cursor->depth);
        }
        else {
            $this->line .= '"';
        }
        foreach ($str as $str) {
            if ($i < $m) {
                $str .= "\n";
            }
            if (0 < $this->maxStringWidth && $this->maxStringWidth < ($len = mb_strlen($str, 'UTF-8'))) {
                $str = mb_substr($str, 0, $this->maxStringWidth, 'UTF-8');
                $lineCut = $len - $this->maxStringWidth;
            }
            if ($m && 0 < $cursor->depth) {
                $this->line .= $this->indentPad;
            }
            if ('' !== $str) {
                $this->line .= $this->style('str', $str, $attr);
            }
            if ($i++ == $m) {
                if ($m) {
                    if ('' !== $str) {
                        $this->dumpLine($cursor->depth);
                        if (0 < $cursor->depth) {
                            $this->line .= $this->indentPad;
                        }
                    }
                    $this->line .= '"""';
                }
                else {
                    $this->line .= '"';
                }
                if ($cut < 0) {
                    $this->line .= '…';
                    $lineCut = 0;
                }
                elseif ($cut) {
                    $lineCut += $cut;
                }
            }
            if ($lineCut) {
                $this->line .= '…' . $lineCut;
                $lineCut = 0;
            }
            if ($i > $m) {
                $this->endValue($cursor);
            }
            else {
                $this->dumpLine($cursor->depth);
            }
        }
    }
}
RSS feed
Powered by Drupal