@@ -27,9 +27,28 @@ public function apply(
2727
2828 $ valueString = trim ((string )$ detailValue ["content " ], " ' \"" );
2929 $ equalsType = $ detailType ["content " ];
30- $ expression ->appendFragment (
31- $ this ->buildExpression ($ attribute , $ valueString , $ equalsType )
32- );
30+ $ condition = $ this ->buildCondition ($ attribute , $ valueString , $ equalsType );
31+ $ expression ->appendFragment ("[ {$ condition }] " );
32+ }
33+
34+ /** @param array<string, mixed> $token */
35+ public function buildConditionFromToken (array $ token , bool $ htmlMode ):string {
36+ $ attribute = (string )$ token ["content " ];
37+ if ($ htmlMode ) {
38+ $ attribute = strtolower ($ attribute );
39+ }
40+
41+ $ detail = $ token ["detail " ] ?? null ;
42+ $ detailType = $ detail [0 ] ?? null ;
43+ $ detailValue = $ detail [1 ] ?? null ;
44+
45+ if (!$ this ->hasEqualsType ($ detailType )) {
46+ return "@ {$ attribute }" ;
47+ }
48+
49+ $ valueString = trim ((string )$ detailValue ["content " ], " ' \"" );
50+ $ equalsType = $ detailType ["content " ];
51+ return $ this ->buildCondition ($ attribute , $ valueString , $ equalsType );
3352 }
3453
3554 /** @param array<string, mixed>|null $detailType */
@@ -38,32 +57,32 @@ private function hasEqualsType(?array $detailType):bool {
3857 && $ detailType ["type " ] === "attribute_equals " ;
3958 }
4059
41- private function buildExpression (
60+ private function buildCondition (
4261 string $ attribute ,
4362 string $ value ,
4463 string $ equalsType
4564 ):string {
4665 return match ($ equalsType ) {
47- Translator::EQUALS_EXACT => "[ @ {$ attribute }= \"{$ value }\"] " ,
48- Translator::EQUALS_CONTAINS => "[ contains(@ {$ attribute }, \"{$ value }\")] " ,
49- Translator::EQUALS_CONTAINS_WORD => "[ "
66+ Translator::EQUALS_EXACT => "@ {$ attribute }= \"{$ value }\"" ,
67+ Translator::EQUALS_CONTAINS => "contains(@ {$ attribute }, \"{$ value }\") " ,
68+ Translator::EQUALS_CONTAINS_WORD => ""
5069 . "contains(concat( \" \",@ {$ attribute }, \" \"), "
5170 . "concat( \" \", \"{$ value }\", \" \")) "
52- . "] " ,
53- Translator::EQUALS_OR_STARTS_WITH_HYPHENATED => "[ "
71+ . "" ,
72+ Translator::EQUALS_OR_STARTS_WITH_HYPHENATED => ""
5473 . "@ {$ attribute }= \"{$ value }\" or "
5574 . "starts-with(@ {$ attribute }, \"{$ value }- \") "
56- . "] " ,
57- Translator::EQUALS_STARTS_WITH => "[ "
75+ . "" ,
76+ Translator::EQUALS_STARTS_WITH => ""
5877 . "starts-with(@ {$ attribute }, \"{$ value }\") "
59- . "] " ,
60- Translator::EQUALS_ENDS_WITH => "[ "
78+ . "" ,
79+ Translator::EQUALS_ENDS_WITH => ""
6180 . "substring(@ {$ attribute }, "
6281 . "string-length(@ {$ attribute }) - "
6382 . "string-length( \"{$ value }\") + 1) "
6483 . "= \"{$ value }\""
65- . "] " ,
66- default => "[ @ {$ attribute }] " ,
84+ . "" ,
85+ default => "@ {$ attribute }" ,
6786 };
6887 }
6988}
0 commit comments