Automattic\WooCommerce\Vendor\Pelago\Emogrifier\Utilities
DeclarationBlockParser::parse
Parses a CSS declaration block into property name/value pairs.
Example:
The declaration block
"color: #000; font-weight: bold;"
will be parsed into the following array:
"color" => "#000" "font-weight" => "bold"
Метод класса: DeclarationBlockParser{}
Хуков нет.
Возвращает
Массив
Использование
$DeclarationBlockParser = new DeclarationBlockParser(); $DeclarationBlockParser->parse( $declarationBlock ): array;
- $declarationBlock(строка) (обязательный)
- the CSS declarations block without the curly braces, may be empty.
Код DeclarationBlockParser::parse() DeclarationBlockParser::parse WC 10.4.3
public function parse(string $declarationBlock): array
{
if (isset(self::$cache[$declarationBlock])) {
return self::$cache[$declarationBlock];
}
$preg = new Preg();
$declarations = $preg->split('/;(?!base64|charset)/', $declarationBlock);
$properties = [];
foreach ($declarations as $declaration) {
$matches = [];
if (
$preg->match(
'/^([A-Za-z\\-]+)\\s*:\\s*(.+)$/s',
\trim($declaration),
$matches
)
=== 0
) {
continue;
}
$propertyName = $matches[1];
if ($propertyName === '') {
// This cannot happen since the regular epression matches one or more characters.
throw new \UnexpectedValueException('An empty property name was encountered.', 1727046409);
}
$propertyValue = $matches[2];
$properties[$this->normalizePropertyName($propertyName)] = $propertyValue;
}
self::$cache[$declarationBlock] = $properties;
return $properties;
}