-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathDocument.php
More file actions
96 lines (87 loc) · 3.03 KB
/
Copy pathDocument.php
File metadata and controls
96 lines (87 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
declare(strict_types=1);
namespace Sabberworm\CSS\CSSList;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Parsing\SourceException;
use Sabberworm\CSS\Property\Selector;
use Sabberworm\CSS\RuleSet\RuleSet;
use Sabberworm\CSS\Value\Value;
/**
* 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`).
*/
class Document extends CSSBlockList
{
/**
* @throws SourceException
*
* @internal since V8.8.0
*/
public static function parse(ParserState $parserState): Document
{
$document = new Document($parserState->currentLine());
CSSList::parseList($parserState, $document);
return $document;
}
/**
* Returns all `Value` objects found recursively in `Rule`s in the tree.
*
* @param CSSList|RuleSet|string $element
* the `CSSList` or `RuleSet` to start the search from (defaults to the whole document).
* If a string is given, it is used as rule name filter.
* @param bool $searchInFunctionArguments whether to also return Value objects used as Function arguments.
*
* @return array<int, Value>
*
* @see RuleSet->getRules()
*/
public function getAllValues($element = null, bool $searchInFunctionArguments = false): array
{
$searchString = null;
if ($element === null) {
$element = $this;
} elseif (\is_string($element)) {
$searchString = $element;
$element = $this;
}
/** @var array<int, Value> $result */
$result = [];
$this->allValues($element, $result, $searchString, $searchInFunctionArguments);
return $result;
}
/**
* Returns all `Selector` objects with the requested specificity found recursively in the tree.
*
* Note that this does not yield the full `DeclarationBlock` that the selector belongs to
* (and, currently, there is no way to get to that).
*
* @param string|null $specificitySearch
* An optional filter by specificity.
* May contain a comparison operator and a number or just a number (defaults to "==").
*
* @return array<int, Selector>
* @example `getSelectorsBySpecificity('>= 100')`
*/
public function getSelectorsBySpecificity(?string $specificitySearch = null): array
{
/** @var array<int, Selector> $result */
$result = [];
$this->allSelectors($result, $specificitySearch);
return $result;
}
/**
* Overrides `render()` to make format argument optional.
*/
public function render(?OutputFormat $outputFormat = null): string
{
if ($outputFormat === null) {
$outputFormat = new OutputFormat();
}
return $outputFormat->getFormatter()->comments($this) . $this->renderListContents($outputFormat);
}
public function isRootList(): bool
{
return true;
}
}