css-sanitizer
Classes to parse and sanitize CSS
Loading...
Searching...
No Matches
Wikimedia\CSS\Sanitizer\StyleRuleSanitizer Class Reference

Sanitizes a CSS style rule. More...

+ Inheritance diagram for Wikimedia\CSS\Sanitizer\StyleRuleSanitizer:
+ Collaboration diagram for Wikimedia\CSS\Sanitizer\StyleRuleSanitizer:

Public Member Functions

 __construct (Matcher $selectorMatcher, PropertySanitizer $propertySanitizer, array $options=[])
 
 handlesRule (Rule $rule)
 @inheritDoc
 
- Public Member Functions inherited from Wikimedia\CSS\Sanitizer\RuleSanitizer
 getIndex ()
 Return an integer indicating ordering constraints.
 
- Public Member Functions inherited from Wikimedia\CSS\Sanitizer\Sanitizer
 getSanitizationErrors ()
 Return all sanitization errors seen so far.
 
 stashSanitizationErrors ()
 Temporarily clear sanitization errors.
 
 clearSanitizationErrors ()
 Clear sanitization errors.
 
 sanitize (CSSObject $object)
 Sanitize a CSS object.
 

Protected Member Functions

 doSanitize (CSSObject $object)
 @inheritDoc
 
- Protected Member Functions inherited from Wikimedia\CSS\Sanitizer\RuleSanitizer
 sanitizeDeclarationBlock (SimpleBlock $block, PropertySanitizer $sanitizer)
 Sanitize a block's contents as a DeclarationList, in place.
 
 sanitizeRuleBlock (SimpleBlock $block, array $sanitizers)
 Sanitize a block's contents as a RuleList, in place.
 
 fixPreludeWhitespace (AtRule $rule, $cloneIfNecessary)
 For the whitespace at the start of the prelude.
 
- Protected Member Functions inherited from Wikimedia\CSS\Sanitizer\Sanitizer
 sanitizationError ( $tag, CSSObject $object, array $data=[])
 Record a sanitization error.
 
 sanitizeObj (Sanitizer $sanitizer, CSSObject $object)
 Run another sanitizer over a CSSObject.
 
 sanitizeList (Sanitizer $sanitizer, CSSObjectList $list)
 Run a sanitizer over all CSSObjects in a CSSObjectList.
 
 sanitizeRules (array $ruleSanitizers, RuleList $list)
 Run a set of RuleSanitizers over all rules in a RuleList.
 

Protected Attributes

 $selectorMatcher
 
 $prependSelectors
 
 $hoistableMatcher
 
 $propertySanitizer
 
- Protected Attributes inherited from Wikimedia\CSS\Sanitizer\Sanitizer
 $sanitizationErrors = []
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\CSS\Sanitizer\StyleRuleSanitizer::__construct ( Matcher $selectorMatcher,
PropertySanitizer $propertySanitizer,
array $options = [] )
Parameters
Matcher$selectorMatcherMatcher for valid selectors. Probably from MatcherFactory::cssSelectorList().
PropertySanitizer$propertySanitizerSanitizer to test property declarations. Probably an instance of StylePropertySanitizer.
array$optionsAdditional options
  • prependSelectors: (ComponentValue[]) Prepend this (and a whitespace) to all selectors. Note: $selectorMatcher must capture each selector with the name 'selector'.
  • hoistableComponentMatcher: (Matcher) Component groups (simple selector sequences, in CSS3 Selectors terminology) matched by this will be hoisted before the prepended selector sequence. (To be more precise: the hoisted part is the longest prefix of the selector that only contains matching simple selector sequences and descendant combinators, and is not followed by a non-descendant combinator.) This can be used to allow filtering by top-level conditional classes/IDs emitted by some framework (e.g. html.no-js) while still jailing selectors into some subsection of the content. For example, if prependSelectors is equivalent to '#content' and hoistableComponentMatcher to [html|body]<simple selector>* will turn 'html.no-js body.ltr div.list' into 'html.no-js body.ltr #content div.list'. Note: $selectorMatcher must capture each simple selector group with the name 'simple' and the combinators with 'combinator'.

Member Function Documentation

◆ doSanitize()

Wikimedia\CSS\Sanitizer\StyleRuleSanitizer::doSanitize ( CSSObject $object)
protected

@inheritDoc

Reimplemented from Wikimedia\CSS\Sanitizer\Sanitizer.

◆ handlesRule()

Wikimedia\CSS\Sanitizer\StyleRuleSanitizer::handlesRule ( Rule $rule)

@inheritDoc

Reimplemented from Wikimedia\CSS\Sanitizer\RuleSanitizer.


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