Debian Codegraph @

vendor/wikimedia/css-sanitizer/src/Grammar/CustomPropertyMatcher.php

raw
1 <?php
2 /**
3 * @file
4 * @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
5 */
6
7 namespace Wikimedia\CSS\Grammar;
8
9 use Wikimedia\CSS\Objects\ComponentValueList;
10 use Wikimedia\CSS\Objects\Token;
11
12 /**
13 * Matcher that matches a custom property (a CSS variable) example --name-of-variable
14 *
15 * This utilises regex to match the custom property --[a-zA-Z][a-zA-Z0-9-] without any input validation.
16 *
17 * @see https://www.w3.org/TR/2022/CR-css-variables-1-20220616/#custom-property
18 */
19 class CustomPropertyMatcher extends Matcher {
20
21 /** @inheritDoc */
22 protected function generateMatches( ComponentValueList $values, $start, array $options ) {
23 // @phan-suppress-next-line PhanCoalescingNeverNull
24 $cv = $values[$start] ?? null;
25 if ( $cv instanceof Token && $cv->type() === Token::T_IDENT
26 && preg_match( '/^\-\-[a-zA-Z][a-zA-Z0-9-]*$/', $cv->value() ) ) {
27 yield $this->makeMatch( $values, $start, $this->next( $values, $start, $options ) );
28 }
29 }
30 }