StyleRule.php
40 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Pelago\Emogrifier\Css; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Sabberworm\CSS\Property\Selector; |
| 6 | use MailPoetVendor\Sabberworm\CSS\RuleSet\DeclarationBlock; |
| 7 | class StyleRule |
| 8 | { |
| 9 | private $declarationBlock; |
| 10 | private $containingAtRule; |
| 11 | public function __construct(DeclarationBlock $declarationBlock, string $containingAtRule = '') |
| 12 | { |
| 13 | $this->declarationBlock = $declarationBlock; |
| 14 | $this->containingAtRule = \trim($containingAtRule); |
| 15 | } |
| 16 | public function getSelectors() : array |
| 17 | { |
| 18 | $selectors = $this->declarationBlock->getSelectors(); |
| 19 | return \array_map(static function (Selector $selector) : string { |
| 20 | return (string) $selector; |
| 21 | }, $selectors); |
| 22 | } |
| 23 | public function getDeclarationAsText() : string |
| 24 | { |
| 25 | return \implode(' ', $this->declarationBlock->getRules()); |
| 26 | } |
| 27 | public function hasAtLeastOneDeclaration() : bool |
| 28 | { |
| 29 | return $this->declarationBlock->getRules() !== []; |
| 30 | } |
| 31 | public function getContainingAtRule() : string |
| 32 | { |
| 33 | return $this->containingAtRule; |
| 34 | } |
| 35 | public function hasContainingAtRule() : bool |
| 36 | { |
| 37 | return $this->getContainingAtRule() !== ''; |
| 38 | } |
| 39 | } |
| 40 |