AtRuleSet.php
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet; |
| 4 | |
| 5 | use Automattic\WooCommerce\Vendor\Sabberworm\CSS\OutputFormat; |
| 6 | use Automattic\WooCommerce\Vendor\Sabberworm\CSS\Property\AtRule; |
| 7 | |
| 8 | /** |
| 9 | * This class represents rule sets for generic at-rules which are not covered by specific classes, i.e., not |
| 10 | * `@import`, `@charset` or `@media`. |
| 11 | * |
| 12 | * A common example for this is `@font-face`. |
| 13 | */ |
| 14 | class AtRuleSet extends RuleSet implements AtRule |
| 15 | { |
| 16 | /** |
| 17 | * @var string |
| 18 | */ |
| 19 | private $sType; |
| 20 | |
| 21 | /** |
| 22 | * @var string |
| 23 | */ |
| 24 | private $sArgs; |
| 25 | |
| 26 | /** |
| 27 | * @param string $sType |
| 28 | * @param string $sArgs |
| 29 | * @param int $iLineNo |
| 30 | */ |
| 31 | public function __construct($sType, $sArgs = '', $iLineNo = 0) |
| 32 | { |
| 33 | parent::__construct($iLineNo); |
| 34 | $this->sType = $sType; |
| 35 | $this->sArgs = $sArgs; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @return string |
| 40 | */ |
| 41 | public function atRuleName() |
| 42 | { |
| 43 | return $this->sType; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @return string |
| 48 | */ |
| 49 | public function atRuleArgs() |
| 50 | { |
| 51 | return $this->sArgs; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @return string |
| 56 | * |
| 57 | * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. |
| 58 | */ |
| 59 | public function __toString() |
| 60 | { |
| 61 | return $this->render(new OutputFormat()); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @param OutputFormat|null $oOutputFormat |
| 66 | * |
| 67 | * @return string |
| 68 | */ |
| 69 | public function render($oOutputFormat) |
| 70 | { |
| 71 | $sResult = $oOutputFormat->comments($this); |
| 72 | $sArgs = $this->sArgs; |
| 73 | if ($sArgs) { |
| 74 | $sArgs = ' ' . $sArgs; |
| 75 | } |
| 76 | $sResult .= "@{$this->sType}$sArgs{$oOutputFormat->spaceBeforeOpeningBrace()}{"; |
| 77 | $sResult .= $this->renderRules($oOutputFormat); |
| 78 | $sResult .= '}'; |
| 79 | return $sResult; |
| 80 | } |
| 81 | } |
| 82 |