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
|
<?php
declare(strict_types=1);
namespace Pelago\Emogrifier\Css;
use Sabberworm\CSS\Property\Selector; use Sabberworm\CSS\RuleSet\DeclarationBlock;
/** * This class represents a CSS style rule, including selectors, a declaration block, and an optional containing at-rule. * * @internal */ class StyleRule { /** * @var DeclarationBlock */ private $declarationBlock;
/** * @var string */ private $containingAtRule;
/** * @param DeclarationBlock $declarationBlock * @param string $containingAtRule e.g. `@media screen and (max-width: 480px)` */ public function __construct(DeclarationBlock $declarationBlock, string $containingAtRule = '') { $this->declarationBlock = $declarationBlock; $this->containingAtRule = \trim($containingAtRule); }
/** * @return array<int, string> the selectors, e.g. `["h1", "p"]` */ public function getSelectors(): array { /** @var array<int, Selector> $selectors */ $selectors = $this->declarationBlock->getSelectors(); return \array_map( static function (Selector $selector): string { return (string)$selector; }, $selectors ); }
/** * @return string the CSS declarations, separated and followed by a semicolon, e.g., `color: red; height: 4px;` */ public function getDeclarationAsText(): string { return \implode(' ', $this->declarationBlock->getRules()); }
/** * Checks whether the declaration block has at least one declaration. */ public function hasAtLeastOneDeclaration(): bool { return $this->declarationBlock->getRules() !== []; }
/** * @returns string e.g. `@media screen and (max-width: 480px)`, or an empty string */ public function getContainingAtRule(): string { return $this->containingAtRule; }
/** * Checks whether the containing at-rule is non-empty and has any non-whitespace characters. */ public function hasContainingAtRule(): bool { return $this->getContainingAtRule() !== ''; } }
|