File tree Expand file tree Collapse file tree 3 files changed +70
-4
lines changed
Expand file tree Collapse file tree 3 files changed +70
-4
lines changed Original file line number Diff line number Diff line change 1212 }
1313 ],
1414 "require" : {
15- "tijsverkoyen /css-to-inline-styles " : " ^2.2 " ,
15+ "symfony /css-selector " : " ^2.7|~3.0 " ,
1616 "twig/twig" : " ^1.26"
1717 },
1818 "autoload" : {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace PageSpecificCss ;
4+
5+ class CssStore
6+ {
7+ /** @var string[] */
8+ private $ styles = [];
9+
10+ public function addCssStyle ($ cssRules )
11+ {
12+ $ this ->styles [] = $ cssRules ;
13+ }
14+
15+ public function getStyles ()
16+ {
17+ return $ this ->styles ;
18+ }
19+
20+ public function compileStyles ()
21+ {
22+ return join ('; ' , $ this ->styles );
23+ }
24+
25+ /**
26+ * @param string $path
27+ *
28+ * @return bool whether the dumping was successful
29+ */
30+ public function dumpStyles ($ path )
31+ {
32+ return file_put_contents ($ path , $ this ->compileStyles ()) === false ;
33+ }
34+
35+
36+ }
Original file line number Diff line number Diff line change 33namespace PageSpecificCss ;
44
55use TijsVerkoyen \CssToInlineStyles \Css \Processor ;
6+ use TijsVerkoyen \CssToInlineStyles \Css \Rule \Rule ;
67use TijsVerkoyen \CssToInlineStyles \CssToInlineStyles ;
78
89class PageSpecificCss extends CssToInlineStyles
910{
1011
11- public function extractCss ($ page )
12+ /**
13+ * @var CssStore
14+ */
15+ private $ cssStore ;
16+
17+ /**
18+ * PageSpecificCss constructor.
19+ */
20+ public function __construct ()
21+ {
22+ parent ::__construct ();
23+
24+ $ this ->cssStore = new CssStore ();
25+
26+ }
27+
28+ /**
29+ * @param string $html the raw html
30+ */
31+ public function processHtmlToStore ($ html )
32+ {
33+ $ this ->cssStore ->addCssStyle ($ this ->extractCss ($ html ));
34+ }
35+
36+ /**
37+ * @param $html
38+ *
39+ * @return string
40+ */
41+ public function extractCss ($ html )
1242 {
13- $ processor = new Processor ();
14- return $ processor -> getRules ( $ processor -> getCssFromStyleTags ( $ page )) ;
43+ // Do something..
44+ return '' ;
1545 }
1646}
You can’t perform that action at this time.
0 commit comments