@@ -93,23 +93,23 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
93
93
// $regexPattern match on: $matches[0] {{section.element(arg.field)}}
94
94
// $matches[1] = section.element
95
95
// $matches[2] = arg.field
96
- $ regexPattern = '/{{([\w.\[\]]+)\(*([\w.$ \']+)*\)*}}/ ' ;
96
+ $ regexPattern = '/{{([\w.\[\]]+)\(*([\w.$ \',\s ]+)*\)*}}/ ' ;
97
97
98
98
foreach ($ this ->parsedActions as $ action ) {
99
99
$ varAttributes = array_intersect ($ this ->varAttributes , array_keys ($ action ->getCustomActionAttributes ()));
100
100
$ newActionAttributes = [];
101
+
101
102
if (!empty ($ varAttributes )) {
102
103
// 1 check to see if we have pertinent var
103
104
foreach ($ varAttributes as $ varAttribute ) {
104
105
$ attributeValue = $ action ->getCustomActionAttributes ()[$ varAttribute ];
105
106
preg_match_all ($ regexPattern , $ attributeValue , $ matches );
106
-
107
107
if (empty ($ matches [0 ])) {
108
108
continue ;
109
109
}
110
110
111
111
//get rid of full match {{arg.field(arg.field)}}
112
- unset ($ matches[ 0 ] );
112
+ array_shift ($ matches );
113
113
114
114
$ newActionAttributes [$ varAttribute ] = $ this ->replaceAttributeArguments (
115
115
$ arguments ,
@@ -141,36 +141,68 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
141
141
*/
142
142
private function replaceAttributeArguments ($ arguments , $ attributeValue , $ matches )
143
143
{
144
- $ matchParametersKey = 2 ;
145
- $ newAttributeVal = $ attributeValue ;
144
+ list ($ mainValueList , $ possibleArgumentsList ) = $ matches ;
146
145
147
- foreach ($ matches as $ key => $ match ) {
148
- foreach ($ match as $ variable ) {
149
- if (empty ($ variable )) {
150
- continue ;
151
- }
152
- // Truncate arg.field into arg. If 'Literal' was passed, variableName will be null.
153
- $ variableName = strstr ($ variable , '. ' , true );
154
- // Check if arguments has a mapping for the given variableName
155
- if ($ variableName == null || !array_key_exists ($ variableName , $ arguments )) {
156
- continue ;
157
- }
158
- $ isPersisted = strstr ($ arguments [$ variableName ], '$ ' );
159
- if ($ isPersisted ) {
160
- $ newAttributeVal = $ this ->replacePersistedArgument (
161
- $ arguments [$ variableName ],
162
- $ attributeValue ,
163
- $ variable ,
164
- $ variableName ,
165
- $ key == $ matchParametersKey ? true : false
166
- );
167
- } else {
168
- $ newAttributeVal = str_replace ($ variableName , $ arguments [$ variableName ], $ attributeValue );
169
- }
146
+ foreach ($ mainValueList as $ index => $ mainValue ) {
147
+ $ possibleArguments = $ possibleArgumentsList [$ index ];
148
+
149
+ $ attributeValue = $ this ->replaceAttributeArgumentInVariable ($ mainValue , $ arguments , $ attributeValue );
150
+
151
+ // Split on commas, trim all values, and finally filter out all FALSE values
152
+ $ argumentList = array_filter (array_map ('trim ' , explode (', ' , $ possibleArguments )));
153
+
154
+ foreach ($ argumentList as $ argumentValue ) {
155
+ $ attributeValue = $ this ->replaceAttributeArgumentInVariable (
156
+ $ argumentValue ,
157
+ $ arguments ,
158
+ $ attributeValue ,
159
+ true
160
+ );
170
161
}
171
162
}
172
163
173
- return $ newAttributeVal ;
164
+ return $ attributeValue ;
165
+ }
166
+
167
+ /**
168
+ * Replace attribute arguments in variable.
169
+ *
170
+ * @param string $variable
171
+ * @param array $arguments
172
+ * @param string $attributeValue
173
+ * @param bool $isInnerArgument
174
+ * @return string
175
+ */
176
+ private function replaceAttributeArgumentInVariable (
177
+ $ variable ,
178
+ $ arguments ,
179
+ $ attributeValue ,
180
+ $ isInnerArgument = false
181
+ ) {
182
+ // Truncate arg.field into arg
183
+ $ variableName = strstr ($ variable , '. ' , true );
184
+ // Check if arguments has a mapping for the given variableName
185
+
186
+ if ($ variableName === false ) {
187
+ $ variableName = $ variable ;
188
+ }
189
+
190
+ if (!array_key_exists ($ variableName , $ arguments )) {
191
+ return $ attributeValue ;
192
+ }
193
+
194
+ $ isPersisted = strstr ($ arguments [$ variableName ], '$ ' );
195
+ if ($ isPersisted ) {
196
+ return $ this ->replacePersistedArgument (
197
+ $ arguments [$ variableName ],
198
+ $ attributeValue ,
199
+ $ variable ,
200
+ $ variableName ,
201
+ $ isInnerArgument
202
+ );
203
+ }
204
+
205
+ return str_replace ($ variableName , $ arguments [$ variableName ], $ attributeValue );
174
206
}
175
207
176
208
/**
@@ -197,11 +229,12 @@ private function replacePersistedArgument($replacement, $attributeValue, $fullVa
197
229
198
230
// parameter replacements require changing of (arg.field) to ($arg.field$)
199
231
if ($ isParameter ) {
200
- $ newAttributeValue = str_replace ($ fullVariable , $ scope . $ fullVariable . $ scope , $ newAttributeValue );
232
+ $ fullReplacement = str_replace ($ variable , trim ($ replacement , '$ ' ), $ fullVariable );
233
+ $ newAttributeValue = str_replace ($ fullVariable , $ scope . $ fullReplacement . $ scope , $ newAttributeValue );
201
234
} else {
202
235
$ newAttributeValue = str_replace ('{{ ' , $ scope , str_replace ('}} ' , $ scope , $ newAttributeValue ));
236
+ $ newAttributeValue = str_replace ($ variable , trim ($ replacement , '$ ' ), $ newAttributeValue );
203
237
}
204
- $ newAttributeValue = str_replace ($ variable , trim ($ replacement , '$ ' ), $ newAttributeValue );
205
238
206
239
return $ newAttributeValue ;
207
240
}
0 commit comments