8
8
9
9
class ActionObject
10
10
{
11
+ /**
12
+ * @var string $mergeKey
13
+ * @var string $type
14
+ * @var array $actionAttributes
15
+ * @var string $linkedAction
16
+ * @var int $orderOffset
17
+ * @var array $resolvedCustomAttributes
18
+ * @var int timeout
19
+ */
11
20
private $ mergeKey ;
12
21
private $ type ;
13
22
private $ actionAttributes = [];
@@ -16,6 +25,16 @@ class ActionObject
16
25
private $ resolvedCustomAttributes = [];
17
26
private $ timeout ;
18
27
28
+ const DATA_ENABLED_ATTRIBUTES = ["userInput " , "parameterArray " ];
29
+
30
+ /**
31
+ * ActionObject constructor.
32
+ * @param string $mergeKey
33
+ * @param string $type
34
+ * @param array $actionAttributes
35
+ * @param string|null $linkedAction
36
+ * @param int $order
37
+ */
19
38
public function __construct ($ mergeKey , $ type , $ actionAttributes , $ linkedAction = null , $ order = 0 )
20
39
{
21
40
$ this ->mergeKey = $ mergeKey ;
@@ -28,11 +47,19 @@ public function __construct($mergeKey, $type, $actionAttributes, $linkedAction =
28
47
}
29
48
}
30
49
50
+ /**
51
+ * This function returns the string property mergeKey.
52
+ * @return string
53
+ */
31
54
public function getMergeKey ()
32
55
{
33
56
return $ this ->mergeKey ;
34
57
}
35
58
59
+ /**
60
+ * This function returns the string property type.
61
+ * @return string
62
+ */
36
63
public function getType ()
37
64
{
38
65
return $ this ->type ;
@@ -52,16 +79,29 @@ public function getCustomActionAttributes()
52
79
return array_merge ($ this ->actionAttributes , $ this ->resolvedCustomAttributes );
53
80
}
54
81
82
+ /**
83
+ * This function returns the string property linkedAction, describing a step to reference for a merge.
84
+ * @return string
85
+ */
55
86
public function getLinkedAction ()
56
87
{
57
88
return $ this ->linkedAction ;
58
89
}
59
90
91
+ /**
92
+ * This function returns the int property orderOffset, describing before or after for a merge.
93
+ * @return int
94
+ */
60
95
public function getOrderOffset ()
61
96
{
62
97
return $ this ->orderOffset ;
63
98
}
64
99
100
+ /**
101
+ * This function returns the int property timeout, this can be set as a result of the use of a section element
102
+ * requiring a wait.
103
+ * @return int
104
+ */
65
105
public function getTimeout ()
66
106
{
67
107
return $ this ->timeout ;
@@ -81,7 +121,7 @@ public function resolveReferences()
81
121
if (empty ($ this ->resolvedCustomAttributes )) {
82
122
$ this ->resolveSelectorReferenceAndTimeout ();
83
123
$ this ->resolveUrlReference ();
84
- $ this ->resolveUserInputReference ();
124
+ $ this ->resolveDataInputReferences ();
85
125
}
86
126
}
87
127
@@ -100,9 +140,11 @@ private function resolveSelectorReferenceAndTimeout()
100
140
}
101
141
$ selector = $ this ->actionAttributes ['selector ' ];
102
142
103
- $ reference = $ this ->findReference ($ selector );
104
- if ($ reference == null ) {
105
- // Nothing to replace
143
+ $ reference = $ this ->findAllReferences ($ selector );
144
+ if (count ($ reference ) == 1 ) {
145
+ $ reference = $ reference [0 ];
146
+ } else {
147
+ // Selectors can only handle a single var reference
106
148
return ;
107
149
}
108
150
@@ -112,8 +154,13 @@ private function resolveSelectorReferenceAndTimeout()
112
154
// Bad section reference
113
155
return ;
114
156
}
157
+
115
158
$ replacement = Section::getElementLocator ($ sectionName , $ elementName );
116
159
160
+ if ($ replacement == null ) {
161
+ // Bad section reference
162
+ return ;
163
+ }
117
164
$ this ->resolvedCustomAttributes ['selector ' ] = str_replace ($ reference , $ replacement , $ selector );
118
165
$ this ->timeout = Section::getElementTimeOut ($ sectionName , $ elementName );
119
166
}
@@ -133,59 +180,70 @@ private function resolveUrlReference()
133
180
}
134
181
$ url = $ this ->actionAttributes ['url ' ];
135
182
136
- $ reference = $ this ->findReference ($ url );
137
- if ($ reference == null ) {
138
- // Nothing to replace
139
- return ;
140
- }
183
+ foreach ($ this ->findAllReferences ($ url ) as $ reference ) {
184
+ $ replacement = null ;
141
185
142
- list ($ pageName ) = $ this ->stripAndSplitReference ($ reference );
143
- $ page = Page::getPage ($ pageName );
144
- if ($ page == null ) {
145
- // Bad page reference
146
- return ;
186
+ // assume this is a page
187
+ list ($ pageName ) = $ this ->stripAndSplitReference ($ reference );
188
+ $ page = Page::getPage ($ pageName );
189
+
190
+ if ($ page != null ) {
191
+ $ replacement = Page::getPageUrl ($ pageName );
192
+ } else {
193
+ // try to resolve as data
194
+ list ($ entityName , $ entityField ) = $ this ->stripAndSplitReference ($ reference );
195
+ $ replacement = DataManager::getInstance ()->getEntity ($ entityName )->getDataByName ($ entityField );
196
+ }
197
+
198
+ if ($ replacement == null ) {
199
+ continue ;
200
+ // Bad var ref
201
+ }
202
+ $ url = str_replace ($ reference , $ replacement , $ url );
147
203
}
148
- $ replacement = $ _ENV ['MAGENTO_BASE_URL ' ] . Page::getPageUrl ($ pageName );
149
204
150
- $ this ->resolvedCustomAttributes ['url ' ] = str_replace ( $ reference , $ replacement , $ url) ;
205
+ $ this ->resolvedCustomAttributes ['url ' ] = $ url ;
151
206
}
152
207
153
-
154
208
/**
155
- * Look up the value for EntityDataObjectName.Key and set it as the userInput attribute in the resolved custom
209
+ * Look up the value for EntityDataObjectName.Key and set it as the corresponding attribute in the resolved custom
156
210
* attributes.
157
211
*
158
212
* e.g. {{CustomerEntityFoo.FirstName}} becomes Jerry
159
213
*
160
214
* @return void
161
215
*/
162
- private function resolveUserInputReference ()
216
+ private function resolveDataInputReferences ()
163
217
{
164
- if (!array_key_exists ('userInput ' , $ this ->actionAttributes )) {
165
- return ;
166
- }
167
- $ userInput = $ this ->actionAttributes ['userInput ' ];
218
+ $ actionAttributeKeys = array_keys ($ this ->actionAttributes );
219
+ $ relevantDataAttributes = array_intersect ($ actionAttributeKeys , ActionObject::DATA_ENABLED_ATTRIBUTES );
168
220
169
- $ reference = $ this ->findReference ($ userInput );
170
- if ($ reference == null ) {
171
- // Nothing to replace
221
+ if (empty ($ relevantDataAttributes )) {
172
222
return ;
173
223
}
174
224
175
- list ($ entityName , $ entityKey ) = $ this ->stripAndSplitReference ($ userInput );
176
- $ entityObj = DataManager::getInstance ()->getEntity ($ entityName );
177
- if ($ entityObj == null ) {
178
- // Bad entity reference
179
- return ;
180
- }
225
+ foreach ($ relevantDataAttributes as $ dataAttribute ) {
226
+ $ varInput = $ this ->actionAttributes [$ dataAttribute ];
181
227
182
- $ replacement = $ entityObj ->getDataByName ($ entityKey );
183
- if ($ replacement == null ) {
184
- // Bad entity.key reference
185
- return ;
186
- }
228
+ foreach ($ this ->findAllReferences ($ varInput ) as $ reference ) {
229
+ list ($ entityName , $ entityKey ) = $ this ->stripAndSplitReference ($ reference );
230
+ $ entityObj = DataManager::getInstance ()->getEntity ($ entityName );
231
+ if ($ entityObj == null ) {
232
+ // Bad entity reference
233
+ continue ;
234
+ }
187
235
188
- $ this ->resolvedCustomAttributes ['userInput ' ] = str_replace ($ reference , $ replacement , $ userInput );
236
+ $ replacement = $ entityObj ->getDataByName ($ entityKey ) ?? null ;
237
+ if ($ replacement == null ) {
238
+ // Bad entity.key reference
239
+ return ;
240
+ }
241
+
242
+ $ varInput = str_replace ($ reference , $ replacement , $ varInput );
243
+ }
244
+
245
+ $ this ->resolvedCustomAttributes [$ dataAttribute ] = $ varInput ;
246
+ }
189
247
}
190
248
191
249
/**
@@ -201,16 +259,16 @@ private function stripAndSplitReference($reference)
201
259
}
202
260
203
261
/**
204
- * Return a {{reference.foo}} if it exists in the string.
262
+ * Return an array of {{reference.foo}} if any exist in the string, otherwise returns an empty array .
205
263
*
206
264
* @param string $str
207
- * @return string|null
265
+ * @return array
208
266
*/
209
- private function findReference ($ str )
267
+ private function findAllReferences ($ str )
210
268
{
211
- preg_match ('/{{[\w.]+}}/ ' , $ str , $ matches );
269
+ preg_match_all ('/{{[\w.]+}}/ ' , $ str , $ matches );
212
270
if (empty ($ matches )) {
213
- return null ;
271
+ return [] ;
214
272
} else {
215
273
return $ matches [0 ];
216
274
}
0 commit comments