Chris@13: '\0', Chris@13: "\t" => '\t', Chris@13: "\n" => '\n', Chris@13: "\v" => '\v', Chris@13: "\f" => '\f', Chris@13: "\r" => '\r', Chris@13: "\033" => '\e', Chris@13: ]; Chris@13: Chris@13: public function __construct(OutputFormatter $formatter, $forceArrayIndexes = false) Chris@13: { Chris@13: $this->formatter = $formatter; Chris@13: $this->forceArrayIndexes = $forceArrayIndexes; Chris@13: parent::__construct(); Chris@13: $this->setColors(false); Chris@13: } Chris@13: Chris@13: /** Chris@13: * {@inheritdoc} Chris@13: */ Chris@13: public function enterHash(Cursor $cursor, $type, $class, $hasChild) Chris@13: { Chris@13: if (Cursor::HASH_INDEXED === $type || Cursor::HASH_ASSOC === $type) { Chris@13: $class = 0; Chris@13: } Chris@13: parent::enterHash($cursor, $type, $class, $hasChild); Chris@13: } Chris@13: Chris@13: /** Chris@13: * {@inheritdoc} Chris@13: */ Chris@13: protected function dumpKey(Cursor $cursor) Chris@13: { Chris@13: if ($this->forceArrayIndexes || Cursor::HASH_INDEXED !== $cursor->hashType) { Chris@13: parent::dumpKey($cursor); Chris@13: } Chris@13: } Chris@13: Chris@13: protected function style($style, $value, $attr = []) Chris@13: { Chris@13: if ('ref' === $style) { Chris@17: $value = \strtr($value, '@', '#'); Chris@13: } Chris@13: Chris@13: $styled = ''; Chris@13: $map = self::$controlCharsMap; Chris@13: $cchr = $this->styles['cchr']; Chris@13: Chris@17: $chunks = \preg_split(self::$controlCharsRx, $value, null, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); Chris@13: foreach ($chunks as $chunk) { Chris@17: if (\preg_match(self::$onlyControlCharsRx, $chunk)) { Chris@13: $chars = ''; Chris@13: $i = 0; Chris@13: do { Chris@17: $chars .= isset($map[$chunk[$i]]) ? $map[$chunk[$i]] : \sprintf('\x%02X', \ord($chunk[$i])); Chris@13: } while (isset($chunk[++$i])); Chris@13: Chris@13: $chars = $this->formatter->escape($chars); Chris@13: $styled .= "<{$cchr}>{$chars}"; Chris@13: } else { Chris@13: $styled .= $this->formatter->escape($chunk); Chris@13: } Chris@13: } Chris@13: Chris@13: $style = $this->styles[$style]; Chris@13: Chris@13: return "<{$style}>{$styled}"; Chris@13: } Chris@13: Chris@13: /** Chris@13: * {@inheritdoc} Chris@13: */ Chris@13: protected function dumpLine($depth, $endOfValue = false) Chris@13: { Chris@13: if ($endOfValue && 0 < $depth) { Chris@13: $this->line .= ','; Chris@13: } Chris@13: $this->line = $this->formatter->format($this->line); Chris@13: parent::dumpLine($depth, $endOfValue); Chris@13: } Chris@13: }