-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRule.php
More file actions
78 lines (73 loc) · 2.13 KB
/
Rule.php
File metadata and controls
78 lines (73 loc) · 2.13 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
<?php
namespace PostCSS;
/**
* Represents a CSS rule: a selector followed by a declaration block.
*
* @link https://github.com/postcss/postcss/blob/master/lib/rule.es6
*
* @example
* $root = \PostCSS\Parser::parse('a{}');
* $rule = $root->first;
* $rule->type //=> 'rule'
* (string) $rule //=> 'a{}'
*
* @property string[] $selectors An array containing the rule's individual selectors. Groups of selectors are split at commas
* @property @deprecated string $_selector Rule->_selector is deprecated. Use Rule->raws->selector
*/
class Rule extends Container
{
/**
* The rule's full selector represented as a string.
*
* @var string|null
*/
public $selector = null;
/**
* @param array $defaults
*/
public function __construct(array $defaults = [])
{
$selectors = null;
if (isset($defaults['selectors'])) {
$selectors = $defaults['selectors'];
unset($defaults['selectors']);
}
parent::__construct($defaults);
$this->type = 'rule';
if ($this->nodes === null) {
$this->nodes = [];
}
if ($selectors !== null) {
$this->selectors = $selectors;
}
}
public function __get($name)
{
switch ($name) {
case 'selectors':
return ListUtil::comma($this->selector);
case '_selector':
return $this->raws->selector;
default:
return parent::__get($name);
}
}
public function __set($name, $value)
{
switch ($name) {
case 'selectors':
if (!$this->selector || !preg_match('/,\s*/', $this->selector, $match)) {
$match = null;
}
$sep = ($match !== null) ? $match[0] : ','.$this->raw('between', 'beforeOpen');
$this->selector = implode($sep, (array) $value);
break;
case '_selector':
$this->raws->selector = $value;
break;
default:
parent::__set($name, $value);
break;
}
}
}