function OutputFormatter::createStyleFromString
Tries to create new style instance from string.
1 call to OutputFormatter::createStyleFromString()
- OutputFormatter::formatAndWrap in vendor/
symfony/ console/ Formatter/ OutputFormatter.php - Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping).
File
-
vendor/
symfony/ console/ Formatter/ OutputFormatter.php, line 175
Class
- OutputFormatter
- Formatter class for console output.
Namespace
Symfony\Component\Console\FormatterCode
private function createStyleFromString(string $string) : ?OutputFormatterStyleInterface {
if (isset($this->styles[$string])) {
return $this->styles[$string];
}
if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string, $matches, \PREG_SET_ORDER)) {
return null;
}
$style = new OutputFormatterStyle();
foreach ($matches as $match) {
array_shift($match);
$match[0] = strtolower($match[0]);
if ('fg' == $match[0]) {
$style->setForeground(strtolower($match[1]));
}
elseif ('bg' == $match[0]) {
$style->setBackground(strtolower($match[1]));
}
elseif ('href' === $match[0]) {
$url = preg_replace('{\\\\([<>])}', '$1', $match[1]);
$style->setHref($url);
}
elseif ('options' === $match[0]) {
preg_match_all('([^,;]+)', strtolower($match[1]), $options);
$options = array_shift($options);
foreach ($options as $option) {
$style->setOption($option);
}
}
else {
return null;
}
}
return $style;
}