Skip to content

Commit 5817615

Browse files
committed
Clone objects in all includes
1 parent 50355e5 commit 5817615

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/aleksip/DataTransformPlugin/DataTransformer.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ protected function processPattern($pattern)
5656
$patternSpecificData =
5757
$this->processData(Data::getPatternSpecificData($pattern))
5858
;
59-
// Clone objects in possible default global data.
6059
$dataStore = Data::get();
6160
foreach (array_keys($patternSpecificData) as $key) {
6261
if (!isset($dataStore['patternSpecific'][$pattern]['data'][$key])) {
6362
// Value is default global data.
64-
// TODO: Array support.
6563
if (is_object($dataStore[$key])) {
6664
$patternSpecificData[$key] = clone $dataStore[$key];
6765
}
@@ -137,6 +135,9 @@ public function getProcessedPatternSpecificData($pattern, $extraData = array())
137135
protected function renderPattern($pattern, $data)
138136
{
139137
if (isset($this->patternDataStore[$pattern]['patternRaw'])) {
138+
foreach (array_keys($data) as $key) {
139+
$data = $this->cloneObjects($data, $key);
140+
}
140141
$pattern = $this->env->render(
141142
$this->patternDataStore[$pattern]['patternRaw'],
142143
$data
@@ -145,4 +146,20 @@ protected function renderPattern($pattern, $data)
145146

146147
return $pattern;
147148
}
149+
150+
protected function cloneObjects($data, $key)
151+
{
152+
$value = $data[$key];
153+
if (is_array($value)) {
154+
foreach (array_keys($value) as $subKey) {
155+
$value = $this->cloneObjects($value, $subKey);
156+
}
157+
$data[$key] = $value;
158+
}
159+
elseif (is_object($value)) {
160+
$data[$key] = clone $value;
161+
}
162+
163+
return $data;
164+
}
148165
}

0 commit comments

Comments
 (0)