File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
src/Symfony/Component/CssSelector Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 2727class CssSelectorConverter
2828{
2929 private $ translator ;
30+ private $ html ;
31+
32+ private static $ xmlCache = [];
33+ private static $ htmlCache = [];
3034
3135 /**
3236 * @param bool $html Whether HTML support should be enabled. Disable it for XML documents
3337 */
3438 public function __construct (bool $ html = true )
3539 {
3640 $ this ->translator = new Translator ();
41+ $ this ->html = $ html ;
3742
38- if ($ html ) {
43+ if ($ this -> html ) {
3944 $ this ->translator ->registerExtension (new HtmlExtension ($ this ->translator ));
4045 }
4146
@@ -57,6 +62,18 @@ public function __construct(bool $html = true)
5762 */
5863 public function toXPath (string $ cssExpr , string $ prefix = 'descendant-or-self:: ' )
5964 {
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+
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 );
6178 }
6279}
You can’t perform that action at this time.
0 commit comments