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