DeclarationBlock
extends RuleSet
in package
This class represents a `RuleSet` constrained by a `Selector`.
It contains an array of selector objects (comma-separated in the CSS) as well as the rules to be applied to the matching elements.
Declaration blocks usually appear directly inside a Document or another CSSList (mostly a MediaQuery).
Table of Contents
- $aRules : array<string, array<int<0, max>, Rule>>
- the rules in this rule set, using the property name as the key, with potentially multiple rules per property name.
- $aSelectors : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
- __construct() : mixed
- __toString() : string
- addComments() : void
- addRule() : void
- createBackgroundShorthand() : void
- createBorderShorthand() : void
- Combines `border-color`, `border-style` and `border-width` into `border`.
- createDimensionsShorthand() : void
- Looks for long format CSS dimensional properties (margin, padding, border-color, border-style and border-width) and converts them into shorthand CSS properties.
- createFontShorthand() : void
- Looks for long format CSS font properties (e.g. `font-weight`) and tries to convert them into a shorthand CSS `font` property.
- createListStyleShorthand() : void
- createShorthandProperties() : void
- createShorthands() : void
- Creates shorthand declarations (e.g. `margin` or `font`) whenever possible.
- expandBackgroundShorthand() : void
- Converts shorthand background declarations (e.g. `background: url("chess.png") gray 50% repeat fixed;`) into their constituent parts.
- expandBorderShorthand() : void
- Splits shorthand border declarations (e.g. `border: 1px red;`).
- expandDimensionsShorthand() : void
- Splits shorthand dimensional declarations (e.g. `margin: 0px auto;`) into their constituent parts.
- expandFontShorthand() : void
- Converts shorthand font declarations (e.g. `font: 300 italic 11px/14px verdana, helvetica, sans-serif;`) into their constituent parts.
- expandListStyleShorthand() : void
- expandShorthands() : void
- Splits shorthand declarations (e.g. `margin` or `font`) into their constituent parts.
- getComments() : array<string, Comment>
- getRules() : array<int, Rule>
- Returns all rules matching the given rule name
- getRulesAssoc() : array<string, Rule>
- Returns all rules matching the given pattern and returns them in an associative array with the rule’s name as keys. This method exists mainly for backwards-compatibility and is really only partially useful.
- getSelector() : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
- getSelectors() : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
- removeAllRules() : mixed
- removeMatchingRules() : mixed
- Removes rules by property name or search pattern.
- removeRule() : mixed
- Removes a `Rule` from this `RuleSet` by identity.
- removeSelector() : bool
- Remove one of the selectors of the block.
- render() : string
- setComments() : void
- setRules() : void
- Overrides all the rules of this set.
- setSelector() : void
- setSelectors() : mixed
- renderRules() : string
Properties
$aRules
the rules in this rule set, using the property name as the key, with potentially multiple rules per property name.
private
array<string, array<int<0, max>, Rule>>
$aRules
$aSelectors
private
array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
$aSelectors
Methods
__construct()
public
__construct(int $iLineNo) : mixed
Parameters
- $iLineNo : int
Return values
mixed —__toString()
public
__toString() : string
Tags
Return values
string —addComments()
public
addComments(array<string, Comment> $aComments) : void
Parameters
- $aComments : array<string, Comment>
Return values
void —addRule()
public
addRule(Rule $oRule[, Rule|null $oSibling = null ]) : void
Parameters
Return values
void —createBackgroundShorthand()
public
createBackgroundShorthand() : void
Tags
Return values
void —createBorderShorthand()
Combines `border-color`, `border-style` and `border-width` into `border`.
public
createBorderShorthand() : void
Should be run after create_dimensions_shorthand!
Tags
Return values
void —createDimensionsShorthand()
Looks for long format CSS dimensional properties (margin, padding, border-color, border-style and border-width) and converts them into shorthand CSS properties.
public
createDimensionsShorthand() : void
Tags
Return values
void —createFontShorthand()
Looks for long format CSS font properties (e.g. `font-weight`) and tries to convert them into a shorthand CSS `font` property.
public
createFontShorthand() : void
At least font-size AND font-family must be present in order to create a shorthand declaration.
Tags
Return values
void —createListStyleShorthand()
public
createListStyleShorthand() : void
Tags
Return values
void —createShorthandProperties()
public
createShorthandProperties(array<array-key, string> $aProperties, string $sShorthand) : void
Parameters
- $aProperties : array<array-key, string>
- $sShorthand : string
Tags
Return values
void —createShorthands()
Creates shorthand declarations (e.g. `margin` or `font`) whenever possible.
public
createShorthands() : void
Tags
Return values
void —expandBackgroundShorthand()
Converts shorthand background declarations (e.g. `background: url("chess.png") gray 50% repeat fixed;`) into their constituent parts.
public
expandBackgroundShorthand() : void
Tags
Return values
void —expandBorderShorthand()
Splits shorthand border declarations (e.g. `border: 1px red;`).
public
expandBorderShorthand() : void
Additional splitting happens in expandDimensionsShorthand.
Multiple borders are not yet supported as of 3.
Tags
Return values
void —expandDimensionsShorthand()
Splits shorthand dimensional declarations (e.g. `margin: 0px auto;`) into their constituent parts.
public
expandDimensionsShorthand() : void
Handles margin, padding, border-color, border-style and border-width.
Tags
Return values
void —expandFontShorthand()
Converts shorthand font declarations (e.g. `font: 300 italic 11px/14px verdana, helvetica, sans-serif;`) into their constituent parts.
public
expandFontShorthand() : void
Tags
Return values
void —expandListStyleShorthand()
public
expandListStyleShorthand() : void
Tags
Return values
void —expandShorthands()
Splits shorthand declarations (e.g. `margin` or `font`) into their constituent parts.
public
expandShorthands() : void
Tags
Return values
void —getComments()
public
getComments() : array<string, Comment>
Return values
array<string, Comment> —getRules()
Returns all rules matching the given rule name
public
getRules([Rule|string|null $mRule = null ]) : array<int, Rule>
Parameters
- $mRule : Rule|string|null = null
-
Pattern to search for. If null, returns all rules. If the pattern ends with a dash, all rules starting with the pattern are returned as well as one matching the pattern with the dash excluded. Passing a
Rulefor this parameter is deprecated in version 8.9.0, and will not work from v9.0. CallgetRules($rule->getRule())instead.
Tags
Return values
array<int, Rule> —getRulesAssoc()
Returns all rules matching the given pattern and returns them in an associative array with the rule’s name as keys. This method exists mainly for backwards-compatibility and is really only partially useful.
public
getRulesAssoc([Rule|string|null $mRule = null ]) : array<string, Rule>
Note: This method loses some information: Calling this (with an argument of background-) on a declaration block
like { background-color: green; background-color; rgba(0, 127, 0, 0.7); } will only yield an associative array
containing the rgba-valued rule while getRules() would yield an indexed array containing both.
Parameters
- $mRule : Rule|string|null = null
-
$mRule Pattern to search for. If null, returns all rules. If the pattern ends with a dash, all rules starting with the pattern are returned as well as one matching the pattern with the dash excluded. Passing a
Rulefor this parameter is deprecated in version 8.9.0, and will not work from v9.0. CallgetRulesAssoc($rule->getRule())instead.
Return values
array<string, Rule> —getSelector()
public
getSelector() : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
Tags
Return values
array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string> —getSelectors()
public
getSelectors() : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>
Return values
array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string> —removeAllRules()
public
removeAllRules() : mixed
Return values
mixed —removeMatchingRules()
Removes rules by property name or search pattern.
public
removeMatchingRules(string $searchPattern) : mixed
Parameters
- $searchPattern : string
-
pattern to remove. If the pattern ends in a dash, all rules starting with the pattern are removed as well as one matching the pattern with the dash excluded.
Return values
mixed —removeRule()
Removes a `Rule` from this `RuleSet` by identity.
public
removeRule(Rule|string|null $mRule) : mixed
Parameters
- $mRule : Rule|string|null
-
Ruleto remove. Passing astringornullis deprecated in version 8.9.0, and will no longer work from v9.0. UseremoveMatchingRules()orremoveAllRules()instead.
Return values
mixed —removeSelector()
Remove one of the selectors of the block.
public
removeSelector(Selector|string $mSelector) : bool
Parameters
- $mSelector : Selector|string
Return values
bool —render()
public
render(OutputFormat|null $oOutputFormat) : string
Parameters
- $oOutputFormat : OutputFormat|null
Tags
Return values
string —setComments()
public
setComments(array<string, Comment> $aComments) : void
Parameters
- $aComments : array<string, Comment>
Return values
void —setRules()
Overrides all the rules of this set.
public
setRules(array<array-key, Rule> $aRules) : void
Parameters
- $aRules : array<array-key, Rule>
-
The rules to override with.
Return values
void —setSelector()
public
setSelector(Selector|string $mSelector[, CSSList|null $oList = null ]) : void
Parameters
Tags
Return values
void —setSelectors()
public
setSelectors(array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>|string $mSelector[, CSSList|null $oList = null ]) : mixed
Parameters
- $mSelector : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Selector|string>|string
- $oList : CSSList|null = null
Tags
Return values
mixed —renderRules()
protected
renderRules(OutputFormat $oOutputFormat) : string
Parameters
- $oOutputFormat : OutputFormat
