Document
extends CSSBlockList
in package
This class represents the root of a parsed CSS file. It contains all top-level CSS contents: mostly declaration blocks, but also any at-rules encountered (`Import` and `Charset`).
Table of Contents
- __construct() : mixed
- __toString() : string
- addComments() : void
- append() : void
- Appends an item to the list of contents.
- createShorthands() : void
- Create shorthands properties whenever possible.
- expandShorthands() : void
- Expands all shorthand properties to their long value.
- getAllDeclarationBlocks() : array<int, DeclarationBlock>
- Gets all `DeclarationBlock` objects recursively, no matter how deeply nested the selectors are.
- getAllRuleSets() : array<int, RuleSet>
- Returns all `RuleSet` objects recursively found in the tree, no matter how deeply nested the rule sets are.
- getAllSelectors() : array<int, DeclarationBlock>
- Gets all `DeclarationBlock` objects recursively.
- getAllValues() : array<int, Value>
- Returns all `Value` objects found recursively in `Rule`s in the tree.
- getComments() : array<array-key, Comment>
- getContents() : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet\RuleSet|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Import|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Charset|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\CSSList\CSSList>
- Returns the stored items.
- getSelectorsBySpecificity() : array<int, Selector>
- Returns all `Selector` objects with the requested specificity found recursively in the tree.
- insertBefore() : mixed
- Inserts an item in the CSS list before its sibling. If the desired sibling cannot be found, the item is appended at the end.
- isRootList() : bool
- prepend() : void
- Prepends an item to the list of contents.
- remove() : bool
- Removes an item from the CSS list.
- removeDeclarationBlockBySelector() : void
- Removes a declaration block from the CSS list if it matches all given selectors.
- render() : string
- Overrides `render()` to make format argument optional.
- replace() : bool
- Replaces an item from the CSS list.
- setComments() : void
- setContents() : mixed
- splice() : void
- Splices the list of contents.
- allDeclarationBlocks() : void
- allRuleSets() : void
- allSelectors() : void
- allValues() : void
- renderListContents() : string
- identifierIs() : bool
- Tests an identifier for a given value. Since identifiers are all keywords, they can be vendor-prefixed.
- parseAtRule() : AtRuleBlockList|KeyFrame|Charset|CSSNamespace|Import|AtRuleSet|null
- parseListItem() : AtRuleBlockList|KeyFrame|Charset|CSSNamespace|Import|AtRuleSet|DeclarationBlock|null|false
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<array-key, Comment> $aComments) : void
Parameters
- $aComments : array<array-key, Comment>
Return values
void —append()
Appends an item to the list of contents.
public
append(RuleSet|CSSList|Import|Charset $oItem) : void
Parameters
Return values
void —createShorthands()
Create shorthands properties whenever possible.
public
createShorthands() : void
Tags
Return values
void —expandShorthands()
Expands all shorthand properties to their long value.
public
expandShorthands() : void
Tags
Return values
void —getAllDeclarationBlocks()
Gets all `DeclarationBlock` objects recursively, no matter how deeply nested the selectors are.
public
getAllDeclarationBlocks() : array<int, DeclarationBlock>
Aliased as getAllSelectors().
Return values
array<int, DeclarationBlock> —getAllRuleSets()
Returns all `RuleSet` objects recursively found in the tree, no matter how deeply nested the rule sets are.
public
getAllRuleSets() : array<int, RuleSet>
Return values
array<int, RuleSet> —getAllSelectors()
Gets all `DeclarationBlock` objects recursively.
public
getAllSelectors() : array<int, DeclarationBlock>
Tags
Return values
array<int, DeclarationBlock> —getAllValues()
Returns all `Value` objects found recursively in `Rule`s in the tree.
public
getAllValues([CSSElement|string|null $element = null ][, string|bool|null $ruleSearchPatternOrSearchInFunctionArguments = null ][, bool $searchInFunctionArguments = false ]) : array<int, Value>
Parameters
- $element : CSSElement|string|null = null
-
This is the
CSSListorRuleSetto start the search from (defaults to the whole document). If a string is given, it is used as a rule name filter. Passing a string for this parameter is deprecated in version 8.9.0, and will not work from v9.0; use the following parameter to pass a rule name filter instead. - $ruleSearchPatternOrSearchInFunctionArguments : string|bool|null = null
-
This allows filtering rules by property name (e.g. if "color" is passed, only
Values fromcolorproperties will be returned, or if "font-" is provided,Values from all font rules, likefont-size, and includingfontitself, will be returned). If a Boolean is provided, it is treated as the$searchInFunctionArgumentsargument. Passing a Boolean for this parameter is deprecated in version 8.9.0, and will not work from v9.0; use the$searchInFunctionArgumentsparameter instead. - $searchInFunctionArguments : bool = false
-
whether to also return Value objects used as Function arguments.
Tags
Return values
array<int, Value> —getComments()
public
getComments() : array<array-key, Comment>
Return values
array<array-key, Comment> —getContents()
Returns the stored items.
public
getContents() : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet\RuleSet|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Import|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Charset|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\CSSList\CSSList>
Return values
array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet\RuleSet|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Import|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Charset|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\CSSList\CSSList> —getSelectorsBySpecificity()
Returns all `Selector` objects with the requested specificity found recursively in the tree.
public
getSelectorsBySpecificity([string|null $sSpecificitySearch = null ]) : array<int, Selector>
Note that this does not yield the full DeclarationBlock that the selector belongs to
(and, currently, there is no way to get to that).
Parameters
- $sSpecificitySearch : string|null = null
-
An optional filter by specificity. May contain a comparison operator and a number or just a number (defaults to "==").
Tags
Return values
array<int, Selector> —insertBefore()
Inserts an item in the CSS list before its sibling. If the desired sibling cannot be found, the item is appended at the end.
public
insertBefore(RuleSet|CSSList|Import|Charset $item, RuleSet|CSSList|Import|Charset $sibling) : mixed
Parameters
Return values
mixed —isRootList()
public
isRootList() : bool
Return values
bool —prepend()
Prepends an item to the list of contents.
public
prepend(RuleSet|CSSList|Import|Charset $oItem) : void
Parameters
Return values
void —remove()
Removes an item from the CSS list.
public
remove(RuleSet|Import|Charset|CSSList $oItemToRemove) : bool
Parameters
- $oItemToRemove : RuleSet|Import|Charset|CSSList
-
May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery)
Return values
bool — whether the item was removedremoveDeclarationBlockBySelector()
Removes a declaration block from the CSS list if it matches all given selectors.
public
removeDeclarationBlockBySelector(DeclarationBlock|array<array-key, Selector>|string $mSelector[, bool $bRemoveAll = false ]) : void
Parameters
- $mSelector : DeclarationBlock|array<array-key, Selector>|string
-
the selectors to match
- $bRemoveAll : bool = false
-
whether to stop at the first declaration block found or remove all blocks
Return values
void —render()
Overrides `render()` to make format argument optional.
public
render([OutputFormat|null $oOutputFormat = null ]) : string
Parameters
- $oOutputFormat : OutputFormat|null = null
Return values
string —replace()
Replaces an item from the CSS list.
public
replace(RuleSet|Import|Charset|CSSList $oOldItem, mixed $mNewItem) : bool
Parameters
- $oOldItem : RuleSet|Import|Charset|CSSList
-
May be a
RuleSet(most likely aDeclarationBlock), anImport, aCharsetor anotherCSSList(most likely aMediaQuery) - $mNewItem : mixed
Return values
bool —setComments()
public
setComments(array<array-key, Comment> $aComments) : void
Parameters
- $aComments : array<array-key, Comment>
Return values
void —setContents()
public
setContents(array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet\RuleSet|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Import|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Charset|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\CSSList\CSSList> $aContents) : mixed
Parameters
- $aContents : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet\RuleSet|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Import|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Charset|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\CSSList\CSSList>
Return values
mixed —splice()
Splices the list of contents.
public
splice(int $iOffset[, int $iLength = null ][, array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet\RuleSet|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\CSSList\CSSList|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Import|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Charset> $mReplacement = null ]) : void
Parameters
- $iOffset : int
- $iLength : int = null
- $mReplacement : array<int, \Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet\RuleSet|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\CSSList\CSSList|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Import|\Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\Charset> = null
Return values
void —allDeclarationBlocks()
protected
allDeclarationBlocks(array<int, DeclarationBlock> &$aResult) : void
Parameters
- $aResult : array<int, DeclarationBlock>
Return values
void —allRuleSets()
protected
allRuleSets(array<int, RuleSet> &$aResult) : void
Parameters
- $aResult : array<int, RuleSet>
Return values
void —allSelectors()
protected
allSelectors(array<int, Selector> &$aResult[, string|null $sSpecificitySearch = null ]) : void
Parameters
- $aResult : array<int, Selector>
- $sSpecificitySearch : string|null = null
Return values
void —allValues()
protected
allValues(CSSElement|string $oElement, array<int, Value> &$aResult[, string|null $sSearchString = null ][, bool $bSearchInFunctionArguments = false ]) : void
Parameters
- $oElement : CSSElement|string
- $aResult : array<int, Value>
- $sSearchString : string|null = null
- $bSearchInFunctionArguments : bool = false
Return values
void —renderListContents()
protected
renderListContents(OutputFormat $oOutputFormat) : string
Parameters
- $oOutputFormat : OutputFormat
Return values
string —identifierIs()
Tests an identifier for a given value. Since identifiers are all keywords, they can be vendor-prefixed.
private
static identifierIs(string $sIdentifier, string $sMatch) : bool
We need to check for these versions too.
Parameters
- $sIdentifier : string
- $sMatch : string
Return values
bool —parseAtRule()
private
static parseAtRule(ParserState $oParserState) : AtRuleBlockList|KeyFrame|Charset|CSSNamespace|Import|AtRuleSet|null
Parameters
- $oParserState : ParserState
Tags
Return values
AtRuleBlockList|KeyFrame|Charset|CSSNamespace|Import|AtRuleSet|null —parseListItem()
private
static parseListItem(ParserState $oParserState, CSSList $oList) : AtRuleBlockList|KeyFrame|Charset|CSSNamespace|Import|AtRuleSet|DeclarationBlock|null|false
Parameters
- $oParserState : ParserState
- $oList : CSSList
