X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/vendor/wikimedia/css-sanitizer/src/Grammar/KeywordMatcher.php diff --git a/vendor/wikimedia/css-sanitizer/src/Grammar/KeywordMatcher.php b/vendor/wikimedia/css-sanitizer/src/Grammar/KeywordMatcher.php new file mode 100644 index 00000000..5854765f --- /dev/null +++ b/vendor/wikimedia/css-sanitizer/src/Grammar/KeywordMatcher.php @@ -0,0 +1,50 @@ +s, but will work for + * other types (case-insensitively) too. For delimiter (or case-sensitive) + * matching, use DelimMatcher. + * + * @see https://www.w3.org/TR/2016/CR-css-values-3-20160929/#component-types + */ +class KeywordMatcher extends Matcher { + /** @var string One of the Token::T_* constants */ + protected $type; + + /** @var array Associative array with keys being the values to match */ + protected $values; + + /** + * @param string|string[] $values Token values to match + * @param array $options Options + * - type: (string) Token type to match. Default is Token::T_IDENT. + */ + public function __construct( $values, array $options = [] ) { + $options += [ + 'type' => Token::T_IDENT, + ]; + + $this->values = array_flip( array_map( 'strtolower', (array)$values ) ); + $this->type = $options['type']; + } + + protected function generateMatches( ComponentValueList $values, $start, array $options ) { + $cv = isset( $values[$start] ) ? $values[$start] : null; + if ( $cv instanceof Token && $cv->type() === $this->type && + isset( $this->values[strtolower( $cv->value() )] ) + ) { + yield $this->makeMatch( $values, $start, $this->next( $values, $start, $options ) ); + } + } +}