private function OutputFormatter::createStyleFromString in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/console/Formatter/OutputFormatter.php \Symfony\Component\Console\Formatter\OutputFormatter::createStyleFromString()
Tries to create new style instance from string.
Parameters
string $string:
Return value
OutputFormatterStyle|bool false if string is not format string
1 call to OutputFormatter::createStyleFromString()
- OutputFormatter::format in vendor/
symfony/ console/ Formatter/ OutputFormatter.php - Formats a message according to the given styles.
File
- vendor/
symfony/ console/ Formatter/ OutputFormatter.php, line 185
Class
- OutputFormatter
- Formatter class for console output.
Namespace
Symfony\Component\Console\FormatterCode
private function createStyleFromString($string) {
if (isset($this->styles[$string])) {
return $this->styles[$string];
}
if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', strtolower($string), $matches, PREG_SET_ORDER)) {
return false;
}
$style = new OutputFormatterStyle();
foreach ($matches as $match) {
array_shift($match);
if ('fg' == $match[0]) {
$style
->setForeground($match[1]);
}
elseif ('bg' == $match[0]) {
$style
->setBackground($match[1]);
}
else {
try {
$style
->setOption($match[1]);
} catch (\InvalidArgumentException $e) {
return false;
}
}
}
return $style;
}