6
6
use Sabberworm \CSS \Parsing \OutputException ;
7
7
use Sabberworm \CSS \Parsing \UnexpectedTokenException ;
8
8
use Sabberworm \CSS \Property \Selector ;
9
+ use Sabberworm \CSS \Property \KeyframeSelector ;
9
10
use Sabberworm \CSS \Rule \Rule ;
10
11
use Sabberworm \CSS \Value \RuleValueList ;
11
12
use Sabberworm \CSS \Value \Value ;
12
13
use Sabberworm \CSS \Value \Size ;
13
14
use Sabberworm \CSS \Value \Color ;
14
15
use Sabberworm \CSS \Value \URL ;
16
+ use Sabberworm \CSS \CSSList \KeyFrame ;
15
17
16
18
/**
17
19
* Declaration blocks are the parts of a css file which denote the rules belonging to a selector.
@@ -26,7 +28,7 @@ public function __construct($iLineNo = 0) {
26
28
$ this ->aSelectors = array ();
27
29
}
28
30
29
- public static function parse (ParserState $ oParserState ) {
31
+ public static function parse (ParserState $ oParserState, $ oList = NULL ) {
30
32
$ aComments = array ();
31
33
$ oResult = new DeclarationBlock ($ oParserState ->currentLine ());
32
34
try {
@@ -42,7 +44,7 @@ public static function parse(ParserState $oParserState) {
42
44
}
43
45
}
44
46
} while (!in_array ($ oParserState ->peek (), array ('{ ' , '} ' )) || $ sStringWrapperChar !== false );
45
- $ oResult ->setSelector (implode ('' , $ aSelectorParts ));
47
+ $ oResult ->setSelector (implode ('' , $ aSelectorParts ), $ oList );
46
48
if ($ oParserState ->comes ('{ ' )) {
47
49
$ oParserState ->consume (1 );
48
50
}
@@ -62,18 +64,25 @@ public static function parse(ParserState $oParserState) {
62
64
}
63
65
64
66
65
- public function setSelectors ($ mSelector ) {
67
+ public function setSelectors ($ mSelector, $ oList = NULL ) {
66
68
if (is_array ($ mSelector )) {
67
69
$ this ->aSelectors = $ mSelector ;
68
70
} else {
69
71
$ this ->aSelectors = explode (', ' , $ mSelector );
70
72
}
71
73
foreach ($ this ->aSelectors as $ iKey => $ mSelector ) {
72
74
if (!($ mSelector instanceof Selector)) {
73
- if (!Selector::isValid ($ mSelector )) {
74
- throw new UnexpectedTokenException ("Selector did not match ' " . Selector::SELECTOR_VALIDATION_RX . "'. " , $ mSelector , "custom " );
75
+ if ($ oList === NULL || !($ oList instanceof KeyFrame)) {
76
+ if (!Selector::isValid ($ mSelector )) {
77
+ throw new UnexpectedTokenException ("Selector did not match ' " . Selector::SELECTOR_VALIDATION_RX . "'. " , $ mSelector , "custom " );
78
+ }
79
+ $ this ->aSelectors [$ iKey ] = new Selector ($ mSelector );
80
+ } else {
81
+ if (!KeyframeSelector::isValid ($ mSelector )) {
82
+ throw new UnexpectedTokenException ("Selector did not match ' " . KeyframeSelector::SELECTOR_VALIDATION_RX . "'. " , $ mSelector , "custom " );
83
+ }
84
+ $ this ->aSelectors [$ iKey ] = new KeyframeSelector ($ mSelector );
75
85
}
76
- $ this ->aSelectors [$ iKey ] = new Selector ($ mSelector );
77
86
}
78
87
}
79
88
}
@@ -102,8 +111,8 @@ public function getSelector() {
102
111
/**
103
112
* @deprecated use setSelectors()
104
113
*/
105
- public function setSelector ($ mSelector ) {
106
- $ this ->setSelectors ($ mSelector );
114
+ public function setSelector ($ mSelector, $ oList = NULL ) {
115
+ $ this ->setSelectors ($ mSelector, $ oList );
107
116
}
108
117
109
118
/**
0 commit comments