@@ -24,25 +24,32 @@ class PageSpecificCss extends CssToInlineStyles
2424 /** @var Rule[] */
2525 private $ rules ;
2626
27+ /** @var HtmlStore */
28+ private $ htmlStore ;
29+
2730 /**
2831 * PageSpecificCss constructor.
29- * @param string $sourceCss path to the source css
3032 */
31- public function __construct ($ sourceCss )
33+ public function __construct ()
3234 {
3335 parent ::__construct ();
3436
3537 $ this ->cssStore = new CssStore ();
38+ $ this ->htmlStore = new HtmlStore ();
3639 $ this ->processor = new Processor ();
37- $ this ->rules = $ this ->processor ->getRules (file_get_contents ($ sourceCss ));
3840 $ this ->cssConverter = new CssSelectorConverter ();
39-
4041 }
4142
42- public function getStore (){
43+ public function getCssStore ()
44+ {
4345 return $ this ->cssStore ;
4446 }
4547
48+ public function getHtmlStore ()
49+ {
50+ return $ this ->htmlStore ;
51+ }
52+
4653 /**
4754 * @param string $html the raw html
4855 */
@@ -51,6 +58,23 @@ public function processHtmlToStore($html)
5158 $ this ->cssStore ->addCssStyles ($ this ->extractCss ($ html ));
5259 }
5360
61+ /**
62+ * @param $sourceCss
63+ */
64+ public function addBaseRules ($ sourceCss )
65+ {
66+ $ this ->rules = array_merge ($ this ->rules , $ this ->processor ->getRules ($ sourceCss ));
67+ }
68+
69+ public function buildExtractedRuleSet ()
70+ {
71+ foreach ($ this ->htmlStore ->getSnippets () as $ htmlSnippet ) {
72+ $ this ->processHtmlToStore ($ htmlSnippet );
73+ }
74+
75+ return $ this ->cssStore ->compileStyles ();
76+ }
77+
5478 /**
5579 * @param $html
5680 *
@@ -82,8 +106,6 @@ public function extractCss($html)
82106
83107 $ applicable_rules = $ this ->groupRulesBySelector ($ applicable_rules );
84108 return $ applicable_rules ;
85-
86-
87109 }
88110
89111 /**
@@ -106,4 +128,11 @@ private function groupRulesBySelector($applicable_rules)
106128
107129 return $ grouped ;
108130 }
131+
132+ public function addHtmlToStore ($ rawHtml )
133+ {
134+ $ this ->htmlStore ->addHtmlSnippet ($ rawHtml );
135+ }
136+
137+
109138}
0 commit comments