Skip to content

Commit 50e7cf8

Browse files
committed
fix(Form): update __clone method to ensure deep cloning of properties and items
fix(form): deep clone form object
1 parent baa3fa4 commit 50e7cf8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Structure/Form/Form.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ public function __construct(
9292
$this->setEncryption($encryption, $encryptionValue);
9393
}
9494

95+
public function __clone()
96+
{
97+
if ($this->properties !== null) {
98+
foreach ($this->properties as $key => $property) {
99+
$this->properties[$key] = clone $property;
100+
}
101+
}
102+
if ($this->items !== null) {
103+
$this->items = clone $this->items;
104+
}
105+
if ($this->value !== null) {
106+
$this->value = clone $this->value;
107+
}
108+
}
109+
95110
public function isRoot(): bool
96111
{
97112
return $this->key === Form::ROOT_KEY;

tests/Structure/Form/FormTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,14 @@ public function testAppendConstValue2()
10351035
'sku' => 'SKU456',
10361036
'qty' => '456',
10371037
],
1038+
[
1039+
'sku' => 'SKU789',
1040+
'qty' => '789',
1041+
],
1042+
[
1043+
'sku' => 'SKU000',
1044+
'qty' => '000',
1045+
],
10381046
],
10391047
],
10401048
];

0 commit comments

Comments
 (0)