css-sanitizer
Classes to parse and sanitize CSS
Wikimedia\CSS\Grammar\MatcherFactory Class Reference

Factory for predefined Grammar matchers. More...

Public Member Functions

 optionalWhitespace ()
 Matcher for optional whitespace. More...
 
 significantWhitespace ()
 Matcher for required whitespace. More...
 
 comma ()
 Matcher for a comma. More...
 
 ident ()
 Matcher for an arbitrary identifier. More...
 
 customIdent (array $exclude=[])
 Matcher for a <custom-ident> More...
 
 string ()
 Matcher for a string. More...
 
 urlstring ( $type)
 Matcher for a string containing a URL. More...
 
 url ( $type)
 Matcher for a URL. More...
 
 cssWideKeywords ()
 CSS-wide value keywords. More...
 
 calc (Matcher $typeMatcher, $type)
 Add calc() support to a basic type matcher. More...
 
 integer ()
 Matcher for an integer value. More...
 
 rawNumber ()
 Matcher for a real number, without calc() More...
 
 number ()
 Matcher for a real number. More...
 
 rawPercentage ()
 Matcher for a percentage value, without calc() More...
 
 percentage ()
 Matcher for a percentage value. More...
 
 lengthPercentage ()
 Matcher for a length-percentage value. More...
 
 frequencyPercentage ()
 Matcher for a frequency-percentage value. More...
 
 anglePercentage ()
 Matcher for a angle-percentage value. More...
 
 timePercentage ()
 Matcher for a time-percentage value. More...
 
 numberPercentage ()
 Matcher for a number-percentage value. More...
 
 dimension ()
 Matcher for a dimension value. More...
 
 length ()
 Matcher for a length value. More...
 
 angle ()
 Matcher for an angle value. More...
 
 time ()
 Matcher for a duration (time) value. More...
 
 frequency ()
 Matcher for a frequency value. More...
 
 resolution ()
 Matcher for a resolution value. More...
 
 color ()
 Matcher for a color value. More...
 
 image ()
 Matcher for an image value. More...
 
 position ()
 Matcher for a position value. More...
 
 cssMediaQuery ( $strict=true)
 Matcher for a CSS media query. More...
 
 cssMediaQueryList ( $strict=true)
 Matcher for a CSS media query list. More...
 
 cssSingleTimingFunction ()
 Matcher for single timing functions from CSS Timing Functions Level 1. More...
 

Static Public Member Functions

static singleton ()
 Return a static instance of the factory. More...
 

Protected Member Functions

 rawInteger ()
 Matcher for an integer value, without calc() More...
 
 zero ()
 Matches the number 0. More...
 
 rawLength ()
 Matcher for a length value, without calc() More...
 
 rawAngle ()
 Matcher for an angle value, without calc() More...
 
 rawTime ()
 Matcher for a duration (time) value, without calc() More...
 
 rawFrequency ()
 Matcher for a frequency value, without calc() More...
 
 colorFuncs ()
 Matchers for color functions. More...
 

Protected Attributes

 $cache = []
 

Static Protected Attributes

static $lengthUnits
 
static $angleUnits = [ 'deg', 'grad', 'rad', 'turn' ]
 
static $timeUnits = [ 's', 'ms' ]
 
static $frequencyUnits = [ 'Hz', 'kHz' ]
 

CSS Selectors Level 3

https://www.w3.org/TR/2018/CR-selectors-3-20180130/#w3cselgrammar

 cssSelectorList ()
 List of selectors (selectors_group) More...
 
 cssSelector ()
 A single selector (selector) More...
 
 cssCombinator ()
 A CSS combinator (combinator) More...
 
 cssSimpleSelectorSeq ()
 A simple selector sequence (simple_selector_sequence) More...
 
 cssTypeSelector ()
 A type selector, i.e. More...
 
 cssNamespacePrefix ()
 A namespace prefix (namespace_prefix) More...
 
 cssUniversal ()
 The universal selector (universal) More...
 
 cssID ()
 An ID selector. More...
 
 cssClass ()
 A class selector (class) More...
 
 cssAttrib ()
 An attribute selector (attrib) More...
 
 cssPseudo ()
 A pseudo-class or pseudo-element (pseudo) More...
 
 cssANplusB ()
 An "AN+B" form. More...
 
 cssNegation ()
 A negation (negation) More...
 

Detailed Description

Factory for predefined Grammar matchers.

Note
For security, the attr() and var() functions are not supported.

Member Function Documentation

◆ angle()

Wikimedia\CSS\Grammar\MatcherFactory::angle ( )

◆ anglePercentage()

Wikimedia\CSS\Grammar\MatcherFactory::anglePercentage ( )

◆ calc()

Wikimedia\CSS\Grammar\MatcherFactory::calc ( Matcher  $typeMatcher,
  $type 
)

Add calc() support to a basic type matcher.

See also
https://www.w3.org/TR/2016/CR-css-values-3-20160929/#calc-notation
Parameters
Matcher$typeMatcherMatcher for the type
string$typeType being matched
Returns
Matcher

◆ color()

Wikimedia\CSS\Grammar\MatcherFactory::color ( )

◆ colorFuncs()

Wikimedia\CSS\Grammar\MatcherFactory::colorFuncs ( )
protected

Matchers for color functions.

Returns
Matcher[]

◆ comma()

Wikimedia\CSS\Grammar\MatcherFactory::comma ( )

Matcher for a comma.

Returns
Matcher

◆ cssANplusB()

Wikimedia\CSS\Grammar\MatcherFactory::cssANplusB ( )

◆ cssAttrib()

Wikimedia\CSS\Grammar\MatcherFactory::cssAttrib ( )

An attribute selector (attrib)

'[' S* [ namespace_prefix ]? IDENT S*
    [ [ PREFIXMATCH |
        SUFFIXMATCH |
        SUBSTRINGMATCH |
        '=' |
        INCLUDES |
        DASHMATCH ] S* [ IDENT | STRING ] S*
    ]? ']'

Captures are set for the attribute, test, and value. Note that these captures will probably be relative to the contents of the SimpleBlock that this matcher matches!

Returns
Matcher

◆ cssClass()

Wikimedia\CSS\Grammar\MatcherFactory::cssClass ( )

A class selector (class)

'.' IDENT
Returns
Matcher

◆ cssCombinator()

Wikimedia\CSS\Grammar\MatcherFactory::cssCombinator ( )

A CSS combinator (combinator)

PLUS S* | GREATER S* | TILDE S* | S+

(combinators can be surrounded by whitespace)

Returns
Matcher

◆ cssID()

Wikimedia\CSS\Grammar\MatcherFactory::cssID ( )

An ID selector.

HASH
Returns
Matcher

◆ cssMediaQuery()

Wikimedia\CSS\Grammar\MatcherFactory::cssMediaQuery (   $strict = true)

Matcher for a CSS media query.

See also
https://www.w3.org/TR/2017/CR-mediaqueries-4-20170905/#mq-syntax
Parameters
bool$strictOnly allow defined query types
Returns
Matcher

◆ cssMediaQueryList()

Wikimedia\CSS\Grammar\MatcherFactory::cssMediaQueryList (   $strict = true)

Matcher for a CSS media query list.

See also
https://www.w3.org/TR/2017/CR-mediaqueries-4-20170905/#mq-syntax
Parameters
bool$strictOnly allow defined query types
Returns
Matcher

◆ cssNamespacePrefix()

Wikimedia\CSS\Grammar\MatcherFactory::cssNamespacePrefix ( )

A namespace prefix (namespace_prefix)

 [ IDENT | '*' ]? '|'
Returns
Matcher

◆ cssNegation()

Wikimedia\CSS\Grammar\MatcherFactory::cssNegation ( )

A negation (negation)

':' not( S* [ type_selector | universal | HASH | class | attrib | pseudo ] S* ')'
Returns
Matcher

◆ cssPseudo()

Wikimedia\CSS\Grammar\MatcherFactory::cssPseudo ( )

A pseudo-class or pseudo-element (pseudo)

':' ':'? [ IDENT | functional_pseudo ]

Where functional_pseudo is

FUNCTION S* expression ')'

Although this actually only matches the pseudo-selectors defined in the following sources:

Returns
Matcher

◆ cssSelector()

Wikimedia\CSS\Grammar\MatcherFactory::cssSelector ( )

A single selector (selector)

simple_selector_sequence [ combinator simple_selector_sequence ]*

Capturing is set up for the simple_selector_sequences (as 'simple') and combinator.

Returns
Matcher

◆ cssSelectorList()

Wikimedia\CSS\Grammar\MatcherFactory::cssSelectorList ( )

List of selectors (selectors_group)

selector [ COMMA S* selector ]*

Capturing is set up for the selectors.

Returns
Matcher

◆ cssSimpleSelectorSeq()

Wikimedia\CSS\Grammar\MatcherFactory::cssSimpleSelectorSeq ( )

A simple selector sequence (simple_selector_sequence)

[ type_selector | universal ]
[ HASH | class | attrib | pseudo | negation ]*
| [ HASH | class | attrib | pseudo | negation ]+

The following captures are set:

  • element: [ type_selector | universal ]
  • id: HASH
  • class: class
  • attrib: attrib
  • pseudo: pseudo
  • negation: negation
Returns
Matcher

◆ cssSingleTimingFunction()

Wikimedia\CSS\Grammar\MatcherFactory::cssSingleTimingFunction ( )

Matcher for single timing functions from CSS Timing Functions Level 1.

See also
https://www.w3.org/TR/2017/WD-css-timing-1-20170221/#single-timing-function-production
Returns
Matcher

◆ cssTypeSelector()

Wikimedia\CSS\Grammar\MatcherFactory::cssTypeSelector ( )

A type selector, i.e.

a tag name (type_selector)

[ namespace_prefix ] ? element_name

where element_name is

IDENT
Returns
Matcher

◆ cssUniversal()

Wikimedia\CSS\Grammar\MatcherFactory::cssUniversal ( )

The universal selector (universal)

[ namespace_prefix ]? '*'
Returns
Matcher

◆ cssWideKeywords()

Wikimedia\CSS\Grammar\MatcherFactory::cssWideKeywords ( )

◆ customIdent()

Wikimedia\CSS\Grammar\MatcherFactory::customIdent ( array  $exclude = [])

Matcher for a <custom-ident>

Note this doesn't implement the semantic restriction about assigning meaning to various idents in a complex value, as CSS Sanitizer doesn't deal with semantics on that level.

See also
https://www.w3.org/TR/2016/CR-css-values-3-20160929/#identifier-value
Parameters
string[]$excludeAdditional values to exclude, all-lowercase.
Returns
Matcher

◆ dimension()

Wikimedia\CSS\Grammar\MatcherFactory::dimension ( )

◆ frequency()

Wikimedia\CSS\Grammar\MatcherFactory::frequency ( )

◆ frequencyPercentage()

Wikimedia\CSS\Grammar\MatcherFactory::frequencyPercentage ( )

◆ ident()

Wikimedia\CSS\Grammar\MatcherFactory::ident ( )

Matcher for an arbitrary identifier.

Returns
Matcher

◆ image()

Wikimedia\CSS\Grammar\MatcherFactory::image ( )

◆ integer()

Wikimedia\CSS\Grammar\MatcherFactory::integer ( )

◆ length()

Wikimedia\CSS\Grammar\MatcherFactory::length ( )

◆ lengthPercentage()

Wikimedia\CSS\Grammar\MatcherFactory::lengthPercentage ( )

◆ number()

Wikimedia\CSS\Grammar\MatcherFactory::number ( )

◆ numberPercentage()

Wikimedia\CSS\Grammar\MatcherFactory::numberPercentage ( )

◆ optionalWhitespace()

Wikimedia\CSS\Grammar\MatcherFactory::optionalWhitespace ( )

Matcher for optional whitespace.

Returns
Matcher

◆ percentage()

Wikimedia\CSS\Grammar\MatcherFactory::percentage ( )

◆ position()

Wikimedia\CSS\Grammar\MatcherFactory::position ( )

◆ rawAngle()

Wikimedia\CSS\Grammar\MatcherFactory::rawAngle ( )
protected

◆ rawFrequency()

Wikimedia\CSS\Grammar\MatcherFactory::rawFrequency ( )
protected

◆ rawInteger()

Wikimedia\CSS\Grammar\MatcherFactory::rawInteger ( )
protected

◆ rawLength()

Wikimedia\CSS\Grammar\MatcherFactory::rawLength ( )
protected

◆ rawNumber()

Wikimedia\CSS\Grammar\MatcherFactory::rawNumber ( )

◆ rawPercentage()

Wikimedia\CSS\Grammar\MatcherFactory::rawPercentage ( )

◆ rawTime()

Wikimedia\CSS\Grammar\MatcherFactory::rawTime ( )
protected

Matcher for a duration (time) value, without calc()

See also
https://www.w3.org/TR/2016/CR-css-values-3-20160929/#time
Returns
Matcher

◆ resolution()

Wikimedia\CSS\Grammar\MatcherFactory::resolution ( )

◆ significantWhitespace()

Wikimedia\CSS\Grammar\MatcherFactory::significantWhitespace ( )

Matcher for required whitespace.

Returns
Matcher

◆ singleton()

static Wikimedia\CSS\Grammar\MatcherFactory::singleton ( )
static

Return a static instance of the factory.

Returns
MatcherFactory

◆ string()

Wikimedia\CSS\Grammar\MatcherFactory::string ( )

Matcher for a string.

See also
https://www.w3.org/TR/2016/CR-css-values-3-20160929/#strings
Warning
If the string will be used as a URL, use self::urlstring() instead.
Returns
Matcher

◆ time()

Wikimedia\CSS\Grammar\MatcherFactory::time ( )

Matcher for a duration (time) value.

See also
https://www.w3.org/TR/2016/CR-css-values-3-20160929/#time
Returns
Matcher

◆ timePercentage()

Wikimedia\CSS\Grammar\MatcherFactory::timePercentage ( )

◆ url()

Wikimedia\CSS\Grammar\MatcherFactory::url (   $type)

Matcher for a URL.

See also
https://www.w3.org/TR/2016/CR-css-values-3-20160929/#urls
Parameters
string$typeType of resource referenced, e.g. "image" or "audio". Not used here, but might be used by a subclass to validate the URL more strictly.
Returns
Matcher

◆ urlstring()

Wikimedia\CSS\Grammar\MatcherFactory::urlstring (   $type)

Matcher for a string containing a URL.

Parameters
string$typeType of resource referenced, e.g. "image" or "audio". Not used here, but might be used by a subclass to validate the URL more strictly.
Returns
Matcher

◆ zero()

Wikimedia\CSS\Grammar\MatcherFactory::zero ( )
protected

Matches the number 0.

Returns
Matcher

Member Data Documentation

◆ $lengthUnits

Wikimedia\CSS\Grammar\MatcherFactory::$lengthUnits
staticprotected
Initial value:
= [ 'em', 'ex', 'ch', 'rem', 'vw', 'vh',
'vmin', 'vmax', 'cm', 'mm', 'Q', 'in', 'pc', 'pt', 'px' ]

The documentation for this class was generated from the following file: