File tree 1 file changed +19
-2
lines changed
src/Symfony/Component/CssSelector
1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 27
27
class CssSelectorConverter
28
28
{
29
29
private $ translator ;
30
+ private $ html ;
31
+
32
+ private static $ xmlCache = [];
33
+ private static $ htmlCache = [];
30
34
31
35
/**
32
36
* @param bool $html Whether HTML support should be enabled. Disable it for XML documents
33
37
*/
34
38
public function __construct (bool $ html = true )
35
39
{
36
40
$ this ->translator = new Translator ();
41
+ $ this ->html = $ html ;
37
42
38
- if ($ html ) {
43
+ if ($ this -> html ) {
39
44
$ this ->translator ->registerExtension (new HtmlExtension ($ this ->translator ));
40
45
}
41
46
@@ -57,6 +62,18 @@ public function __construct(bool $html = true)
57
62
*/
58
63
public function toXPath (string $ cssExpr , string $ prefix = 'descendant-or-self:: ' )
59
64
{
60
- return $ this ->translator ->cssToXPath ($ cssExpr , $ prefix );
65
+ if ($ this ->html ) {
66
+ if (self ::$ htmlCache [$ prefix ][$ cssExpr ] ?? false ) {
67
+ return self ::$ htmlCache [$ prefix ][$ cssExpr ];
68
+ }
69
+
70
+ return self ::$ htmlCache [$ prefix ][$ cssExpr ] = $ this ->translator ->cssToXPath ($ cssExpr , $ prefix );
71
+ }
72
65F0
+
73
+ if (self ::$ xmlCache [$ prefix ][$ cssExpr ] ?? false ) {
74
+ return self ::$ xmlCache [$ prefix ][$ cssExpr ];
75
+ }
76
+
77
+ return self ::$ xmlCache [$ prefix ][$ cssExpr ] = $ this ->translator ->cssToXPath ($ cssExpr , $ prefix );
61
78
}
62
79
}
You can’t perform that action at this time.
0 commit comments