3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Store \Model \Config ;
7
8
8
9
/**
@@ -32,8 +33,8 @@ class Placeholder
32
33
*/
33
34
public function __construct (\Magento \Framework \App \RequestInterface $ request , $ urlPaths , $ urlPlaceholder )
34
35
{
35
- $ this ->request = $ request ;
36
- $ this ->urlPaths = $ urlPaths ;
36
+ $ this ->request = $ request ;
37
+ $ this ->urlPaths = $ urlPaths ;
37
38
$ this ->urlPlaceholder = $ urlPlaceholder ;
38
39
}
39
40
@@ -45,15 +46,46 @@ public function __construct(\Magento\Framework\App\RequestInterface $request, $u
45
46
*/
46
47
public function process (array $ data = [])
47
48
{
48
- foreach (array_keys ($ data ) as $ key ) {
49
- $ this ->_processData ($ data , $ key );
49
+ // check provided arguments
50
+ if (empty ($ data )) {
51
+ return [];
52
+ }
53
+
54
+ // initialize $pointer, $parents and $level variable
55
+ reset ($ data );
56
+ $ pointer = &$ data ;
57
+ $ parents = [];
58
+ $ level = 0 ;
59
+
60
+ while ($ level >= 0 ) {
61
+ $ current = &$ pointer [key ($ pointer )];
62
+ if (is_array ($ current )) {
63
+ reset ($ current );
64
+ $ parents [$ level ] = &$ pointer ;
65
+ $ pointer = &$ current ;
66
+ $ level ++;
67
+ } else {
68
+ $ current = $ this ->_processPlaceholders ($ current , $ data );
69
+
70
+ // move pointer of last queue layer to next element
71
+ // or remove layer if all path elements were processed
72
+ while ($ level >= 0 && next ($ pointer ) === false ) {
73
+ $ level --;
74
+ // removal of last element of $parents is skipped here for better performance
75
+ // on next iteration that element will be overridden
76
+ $ pointer = &$ parents [$ level ];
77
+ }
78
+ }
50
79
}
80
+
51
81
return $ data ;
52
82
}
53
83
54
84
/**
55
85
* Process array data recursively
56
86
*
87
+ * @deprecated This method isn't used in process() implementation anymore
88
+ *
57
89
* @param array &$data
58
90
* @param string $path
59
91
* @return void
@@ -90,7 +122,7 @@ protected function _processPlaceholders($value, $data)
90
122
91
123
if ($ url ) {
92
124
$ value = str_replace ('{{ ' . $ placeholder . '}} ' , $ url , $ value );
93
- } elseif (strpos ($ value , (string ) $ this ->urlPlaceholder ) !== false ) {
125
+ } elseif (strpos ($ value , (string )$ this ->urlPlaceholder ) !== false ) {
94
126
$ distroBaseUrl = $ this ->request ->getDistroBaseUrl ();
95
127
96
128
$ value = str_replace ($ this ->urlPlaceholder , $ distroBaseUrl , $ value );
@@ -113,10 +145,9 @@ protected function _getPlaceholder($value)
113
145
{
114
146
if (is_string ($ value ) && preg_match ('/{{(.*)}}.*/ ' , $ value , $ matches )) {
115
147
$ placeholder = $ matches [1 ];
116
- if ($ placeholder == 'unsecure_base_url ' || $ placeholder == 'secure_base_url ' || strpos (
117
- $ value ,
118
- (string ) $ this ->urlPlaceholder
119
- ) !== false
148
+ if ($ placeholder == 'unsecure_base_url ' ||
149
+ $ placeholder == 'secure_base_url ' ||
150
+ strpos ($ value , (string )$ this ->urlPlaceholder ) !== false
120
151
) {
121
152
return $ placeholder ;
122
153
}
@@ -147,20 +178,22 @@ protected function _getValue($path, array $data)
147
178
/**
148
179
* Set array value by path
149
180
*
181
+ * @deprecated This method isn't used in process() implementation anymore
182
+ *
150
183
* @param array &$container
151
184
* @param string $path
152
185
* @param string $value
153
186
* @return void
154
187
*/
155
188
protected function _setValue (array &$ container , $ path , $ value )
156
189
{
157
- $ segments = explode ('/ ' , $ path );
158
- $ currentPointer = & $ container ;
190
+ $ segments = explode ('/ ' , $ path );
191
+ $ currentPointer = &$ container ;
159
192
foreach ($ segments as $ segment ) {
160
193
if (!isset ($ currentPointer [$ segment ])) {
161
194
$ currentPointer [$ segment ] = [];
162
195
}
163
- $ currentPointer = & $ currentPointer [$ segment ];
196
+ $ currentPointer = &$ currentPointer [$ segment ];
164
197
}
165
198
$ currentPointer = $ value ;
166
199
}
0 commit comments