@@ -728,7 +728,6 @@ public function handleBinding(string $value, string $name, ?DOMElement $node = n
728
728
$ regexArrayBinding = '/^\[([^\]]+)\]$/ ' ;
729
729
$ regexTemplateString = '/^`(?P<content>.+)`$/ ' ;
730
730
$ regexObjectBinding = '/^\{(?<elements>[^\}]+)\}$/ ' ;
731
- $ regexObjectElements = '/[" \']?(?<class>[^" \']+)[" \']?\s*:\s*(?<condition>[^,]+)/x ' ;
732
731
733
732
if ($ value === 'true ' ) {
734
733
$ this ->logger ->debug ('- setAttribute ' . $ name );
@@ -739,43 +738,22 @@ public function handleBinding(string $value, string $name, ?DOMElement $node = n
739
738
$ elements = explode (', ' , $ match [1 ]);
740
739
foreach ($ elements as $ element ) {
741
740
$ element = trim ($ element );
742
- if (preg_match ('/^`.*`$/ ' , $ element )) {
743
- $ element = ' {{ ' . str_replace ('" ' , '\'' , $ this ->refactorTemplateString ($ element )) . ' }} ' ;
741
+ if (preg_match ('/^`(.*)`$/ ' , $ element , $ match )) {
742
+ $ dynamicValues [] = $ this ->handleTemplateStringBinding ($ match [1 ], $ twigOutput );
743
+ // $dynamicValues[] = '{{ ' . str_replace('"', '\'', $this->refactorTemplateString($element)) . ' }}';
744
744
} elseif (preg_match ('/^\{(.*)\}$/ ' , $ element , $ match )) {
745
- [$ value , $ condition ] = explode (': ' , $ match [1 ]);
746
- $ element = ' {% if ' . trim ($ condition ) . ' %}{{ ' .
747
- trim (str_replace ('" ' , '\'' , $ value )) .
748
- '}}{% endif %} ' ;
745
+ $ this ->handleObjectBinding ([$ match [1 ]], $ dynamicValues , $ twigOutput );
746
+ } else {
747
+ $ dynamicValues [] = trim ($ element , '" \'' );
749
748
}
750
- $ dynamicValues [] = trim ($ element , '" \'' );
751
749
}
752
750
} elseif (preg_match ($ regexObjectBinding , $ value , $ matches )) {
753
751
$ this ->logger ->debug ('- object binding ' , ['value ' => $ value ]);
754
-
755
752
$ items = explode (', ' , $ matches ['elements ' ]);
756
-
757
- foreach ($ items as $ item ) {
758
- if (preg_match ($ regexObjectElements , $ item , $ matchElement )) {
759
- $ dynamicValues [] = $ this ->builder ->prepareBindingOutput (
760
- $ this ->builder ->refactorCondition ($ matchElement ['condition ' ]) . ' ? \'' . $ matchElement ['class ' ] . ' \'' ,
761
- $ twigOutput
762
- );
763
- }
764
- }
753
+ $ this ->handleObjectBinding ($ items , $ dynamicValues , $ twigOutput );
765
754
} elseif (preg_match ($ regexTemplateString , $ value , $ matches )) {
766
755
// <div :class="`abc ${someDynamicClass}`">
767
- $ templateStringContent = $ matches ['content ' ];
768
-
769
- preg_match_all ('/\${([^}]+)}/ ' , $ templateStringContent , $ matches , PREG_SET_ORDER );
770
- foreach ($ matches as $ match ) {
771
- $ templateStringContent = str_replace (
772
- $ match [0 ],
773
- $ this ->builder ->prepareBindingOutput ($ this ->builder ->refactorCondition ($ match [1 ]), $ twigOutput ),
774
- $ templateStringContent
775
- );
776
- }
777
-
778
- $ dynamicValues [] = $ templateStringContent ;
756
+ $ dynamicValues [] = $ this ->handleTemplateStringBinding ($ matches ['content ' ], $ twigOutput );
779
757
} else {
780
758
$ value = $ this ->builder ->refactorCondition ($ value );
781
759
$ this ->logger ->debug (sprintf ('- setAttribute "%s" with value "%s" ' , $ name , $ value ));
@@ -791,6 +769,39 @@ public function handleBinding(string $value, string $name, ?DOMElement $node = n
791
769
return $ dynamicValues ;
792
770
}
793
771
772
+ /**
773
+ * @param string[] $items
774
+ * @param string[] $dynamicValues
775
+
776
+ * @throws ReflectionException
777
+ */
778
+ protected function handleObjectBinding (array $ items , array &$ dynamicValues , bool $ twigOutput ): void
779
+ {
780
+ $ regexObjectElements = '/[" \']?(?<class>[^" \']+)[" \']?\s*:\s*(?<condition>[^,]+)/x ' ;
781
+
782
+ foreach ($ items as $ item ) {
783
+ if (preg_match ($ regexObjectElements , $ item , $ matchElement )) {
784
+ $ dynamicValues [] = $ this ->builder ->prepareBindingOutput (
785
+ $ this ->builder ->refactorCondition ($ matchElement ['condition ' ]) . ' ? \'' . $ matchElement ['class ' ] . ' \'' ,
786
+ $ twigOutput
787
+ );
788
+ }
789
+ }
790
+ }
791
+
792
+ protected function handleTemplateStringBinding (string $ templateStringContent , bool $ twigOutput ): string
793
+ {
794
+ preg_match_all ('/\${([^}]+)}/ ' , $ templateStringContent , $ matches , PREG_SET_ORDER );
795
+ foreach ($ matches as $ match ) {
796
+ $ templateStringContent = str_replace (
797
+ $ match [0 ],
798
+ $ this ->builder ->prepareBindingOutput ($ this ->builder ->refactorCondition ($ match [1 ]), $ twigOutput ),
799
+ $ templateStringContent
800
+ );
801
+ }
802
+ return $ templateStringContent ;
803
+ }
804
+
794
805
/**
795
806
* @throws ReflectionException
796
807
*/
0 commit comments