function CliDumper::style
Decorates a value with some style.
Parameters
string $style The type of style being applied:
string $value The value being styled:
array $attr Optional context information:
4 calls to CliDumper::style()
- CliDumper::dumpKey in vendor/
symfony/ var-dumper/ Dumper/ CliDumper.php - Dumps a key in a hash structure.
- CliDumper::dumpScalar in vendor/
symfony/ var-dumper/ Dumper/ CliDumper.php - Dumps a scalar value.
- CliDumper::dumpString in vendor/
symfony/ var-dumper/ Dumper/ CliDumper.php - Dumps a string.
- CliDumper::enterHash in vendor/
symfony/ var-dumper/ Dumper/ CliDumper.php - Dumps while entering an hash.
1 method overrides CliDumper::style()
- HtmlDumper::style in vendor/
symfony/ var-dumper/ Dumper/ HtmlDumper.php - Decorates a value with some style.
File
-
vendor/
symfony/ var-dumper/ Dumper/ CliDumper.php, line 434
Class
- CliDumper
- CliDumper dumps variables for command line output.
Namespace
Symfony\Component\VarDumper\DumperCode
protected function style(string $style, string $value, array $attr = []) : string {
$this->colors ??= $this->supportsColors();
$this->handlesHrefGracefully ??= 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100) && !isset($_SERVER['IDEA_INITIAL_DIRECTORY']);
if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {
$prefix = substr($value, 0, -$attr['ellipsis']);
if ('cli' === \PHP_SAPI && 'path' === $attr['ellipsis-type'] && isset($_SERVER[$pwd = '\\' === \DIRECTORY_SEPARATOR ? 'CD' : 'PWD']) && str_starts_with($prefix, $_SERVER[$pwd])) {
$prefix = '.' . substr($prefix, \strlen($_SERVER[$pwd]));
}
if (!empty($attr['ellipsis-tail'])) {
$prefix .= substr($value, -$attr['ellipsis'], $attr['ellipsis-tail']);
$value = substr($value, -$attr['ellipsis'] + $attr['ellipsis-tail']);
}
else {
$value = substr($value, -$attr['ellipsis']);
}
$value = $this->style('default', $prefix) . $this->style($style, $value);
goto href;
}
$map = static::$controlCharsMap;
$startCchr = $this->colors ? "\x1b[m\x1b[{$this->styles['default']}m" : '';
$endCchr = $this->colors ? "\x1b[m\x1b[{$this->styles[$style]}m" : '';
$value = preg_replace_callback(static::$controlCharsRx, function ($c) use ($map, $startCchr, $endCchr) {
$s = $startCchr;
$c = $c[$i = 0];
do {
$s .= $map[$c[$i]] ?? \sprintf('\\x%02X', \ord($c[$i]));
} while (isset($c[++$i]));
return $s . $endCchr;
}, $value, -1, $cchrCount);
if (!($attr['binary'] ?? false)) {
$value = preg_replace_callback(static::$unicodeCharsRx, function ($c) use (&$cchrCount, $startCchr, $endCchr) {
++$cchrCount;
return $startCchr . '\\u{' . strtoupper(dechex(mb_ord($c[0]))) . '}' . $endCchr;
}, $value);
}
if ($this->colors && '' !== $value) {
if ($cchrCount && "\x1b" === $value[0]) {
$value = substr($value, \strlen($startCchr));
}
else {
$value = "\x1b[{$this->styles[$style]}m" . $value;
}
if ($cchrCount && str_ends_with($value, $endCchr)) {
$value = substr($value, 0, -\strlen($endCchr));
}
else {
$value .= "\x1b[{$this->styles['default']}m";
}
}
href:
if ($this->colors && $this->handlesHrefGracefully) {
if (isset($attr['file']) && ($href = $this->getSourceLink($attr['file'], $attr['line'] ?? 0))) {
if ('note' === $style) {
$value .= "\x1b]8;;{$href}\x1b\\^\x1b]8;;\x1b\\";
}
else {
$attr['href'] = $href;
}
}
if (isset($attr['href'])) {
if ('label' === $style) {
$value .= '^';
}
$value = "\x1b]8;;{$attr['href']}\x1b\\{$value}\x1b]8;;\x1b\\";
}
}
if ('label' === $style && '' !== $value) {
$value .= ' ';
}
if ($this->colors && ($attr['virtual'] ?? false)) {
$value = "\x1b[{$this->styles['virtual']}m" . $value;
}
return $value;
}