@@ -138,12 +138,13 @@ public function extractCss($html)
138
138
$ xPath = new DOMXPath ($ document );
139
139
140
140
$ cssIdentifier = join ('- ' , $ this ->loadedfiles );
141
+ $ htmlIdentifier = md5 ($ html );
141
142
142
143
$ applicable_rules = array_filter (
143
144
$ 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 ()] ;
147
148
}
148
149
149
150
$ expression = $ this ->buildExpressionForSelector ($ rule ->getSelector ());
@@ -152,10 +153,11 @@ function (Rule $rule) use ($xPath, $cssIdentifier) {
152
153
$ elements = $ xPath ->query ($ expression );
153
154
154
155
if ($ elements ->length === 0 ) {
156
+ $ this ->cachedRules [$ cssIdentifier ][$ htmlIdentifier ][$ rule ->getSelector ()] = false ;
155
157
return false ;
156
158
}
157
159
158
- $ this ->cachedRules [$ cssIdentifier ][$ rule ->getSelector ()] = true ;
160
+ $ this ->cachedRules [$ cssIdentifier ][$ htmlIdentifier ][ $ rule ->getSelector ()] = true ;
159
161
160
162
return true ;
161
163
}
@@ -204,7 +206,6 @@ private function buildExpressionForSelector(string $selector)
204
206
return $ expression ;
205
207
}
206
208
207
-
208
209
try {
209
210
$ expression = $ this ->cssConverter ->toXPath ($ selector );
210
211
} catch (ExpressionErrorException $ expressionErrorException ) {
0 commit comments