66use Sabberworm \CSS \Parsing \OutputException ;
77use Sabberworm \CSS \Parsing \UnexpectedTokenException ;
88use Sabberworm \CSS \Property \Selector ;
9+ use Sabberworm \CSS \Property \KeyframeSelector ;
910use Sabberworm \CSS \Rule \Rule ;
1011use Sabberworm \CSS \Value \RuleValueList ;
1112use Sabberworm \CSS \Value \Value ;
1213use Sabberworm \CSS \Value \Size ;
1314use Sabberworm \CSS \Value \Color ;
1415use Sabberworm \CSS \Value \URL ;
16+ use Sabberworm \CSS \CSSList \KeyFrame ;
1517
1618/**
1719 * 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) {
2628 $ this ->aSelectors = array ();
2729 }
2830
29- public static function parse (ParserState $ oParserState ) {
31+ public static function parse (ParserState $ oParserState, $ oList = NULL ) {
3032 $ aComments = array ();
3133 $ oResult = new DeclarationBlock ($ oParserState ->currentLine ());
3234 try {
@@ -42,7 +44,7 @@ public static function parse(ParserState $oParserState) {
4244 }
4345 }
4446 } while (!in_array ($ oParserState ->peek (), array ('{ ' , '} ' )) || $ sStringWrapperChar !== false );
45- $ oResult ->setSelector (implode ('' , $ aSelectorParts ));
47+ $ oResult ->setSelector (implode ('' , $ aSelectorParts ), $ oList );
4648 if ($ oParserState ->comes ('{ ' )) {
4749 $ oParserState ->consume (1 );
4850 }
@@ -62,18 +64,25 @@ public static function parse(ParserState $oParserState) {
6264 }
6365
6466
65- public function setSelectors ($ mSelector ) {
67+ public function setSelectors ($ mSelector, $ oList = NULL ) {
6668 if (is_array ($ mSelector )) {
6769 $ this ->aSelectors = $ mSelector ;
6870 } else {
6971 $ this ->aSelectors = explode (', ' , $ mSelector );
7072 }
7173 foreach ($ this ->aSelectors as $ iKey => $ mSelector ) {
7274 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 );
7585 }
76- $ this ->aSelectors [$ iKey ] = new Selector ($ mSelector );
7786 }
7887 }
7988 }
@@ -102,8 +111,8 @@ public function getSelector() {
102111 /**
103112 * @deprecated use setSelectors()
104113 */
105- public function setSelector ($ mSelector ) {
106- $ this ->setSelectors ($ mSelector );
114+ public function setSelector ($ mSelector, $ oList = NULL ) {
115+ $ this ->setSelectors ($ mSelector, $ oList );
107116 }
108117
109118 /**
0 commit comments