@@ -138,12 +138,13 @@ public function extractCss($html)
138138 $ xPath = new DOMXPath ($ document );
139139
140140 $ cssIdentifier = join ('- ' , $ this ->loadedfiles );
141+ $ htmlIdentifier = md5 ($ html );
141142
142143 $ applicable_rules = array_filter (
143144 $ this ->rules ,
144- function (Rule $ rule ) use ($ xPath , $ cssIdentifier ) {
145- if (isset ($ this ->cachedRules [$ cssIdentifier ][$ rule ->getSelector ()])) {
146- return true ;
145+ function (Rule $ rule ) use ($ xPath , $ cssIdentifier, $ htmlIdentifier ) {
146+ if (isset ($ this ->cachedRules [$ cssIdentifier ][$ htmlIdentifier ][ $ rule ->getSelector ()])) {
147+ return $ this -> cachedRules [ $ cssIdentifier ][ $ htmlIdentifier ][ $ rule -> getSelector ()] ;
147148 }
148149
149150 $ expression = $ this ->buildExpressionForSelector ($ rule ->getSelector ());
@@ -152,10 +153,11 @@ function (Rule $rule) use ($xPath, $cssIdentifier) {
152153 $ elements = $ xPath ->query ($ expression );
153154
154155 if ($ elements ->length === 0 ) {
156+ $ this ->cachedRules [$ cssIdentifier ][$ htmlIdentifier ][$ rule ->getSelector ()] = false ;
155157 return false ;
156158 }
157159
158- $ this ->cachedRules [$ cssIdentifier ][$ rule ->getSelector ()] = true ;
160+ $ this ->cachedRules [$ cssIdentifier ][$ htmlIdentifier ][ $ rule ->getSelector ()] = true ;
159161
160162 return true ;
161163 }
@@ -204,7 +206,6 @@ private function buildExpressionForSelector(string $selector)
204206 return $ expression ;
205207 }
206208
207-
208209 try {
209210 $ expression = $ this ->cssConverter ->toXPath ($ selector );
210211 } catch (ExpressionErrorException $ expressionErrorException ) {
0 commit comments