think\console\output\Formatter::createStyleFromString PHP Метод

createStyleFromString() приватный Метод

根据字符串创建新的样式实例
private createStyleFromString ( string $string ) : Style | boolean
$string string
Результат think\console\output\formatter\Style | boolean
    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 Style();
        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;
    }