You are here

public function HtmlDrupalDumper::dumpString in VarDumper 8

File

src/VarDumper/Dumper/HtmlDrupalDumper.php, line 33

Class

HtmlDrupalDumper
HtmlDrupalDumper dumps variables as HTML.

Namespace

Drupal\vardumper\VarDumper\Dumper

Code

public function dumpString(Cursor $cursor, $str, $bin, $cut) {
  $this
    ->dumpKey($cursor);
  if ($bin) {
    $str = $this
      ->utf8Encode($str);
  }
  if ($str === '') {
    $this->line .= '""';
    $this
      ->dumpLine($cursor->depth, TRUE);
  }
  else {
    $attr = [
      'length' => $cut >= 0 && \function_exists('iconv_strlen') ? iconv_strlen($str, 'UTF-8') + $cut : 0,
      'binary' => $bin,
    ];
    $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 ($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 ($this->maxStringWidth > 0 && $this->maxStringWidth < ($len = iconv_strlen($str, 'UTF-8'))) {
        $str = iconv_substr($str, 0, $this->maxStringWidth, 'UTF-8');
        $lineCut = $len - $this->maxStringWidth;
      }
      if ($m && $cursor->depth > 0) {
        $this->line .= $this->indentPad;
      }
      if ($str !== '') {
        if (mb_substr($str, 0, 5) === 'link:') {
          $this->line .= $this
            ->style('link', $str, $attr);
        }
        else {
          $this->line .= $this
            ->style('str', $str, $attr);
        }
      }
      if ($i++ === $m) {
        if ($m) {
          if ($str !== '') {
            $this
              ->dumpLine($cursor->depth);
            if ($cursor->depth > 0) {
              $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;
      }
      $this
        ->dumpLine($cursor->depth, $i > $m);
    }
  }
}