Skip to content

Commit 6048a4d

Browse files
committed
introduce the new KeyValuecContainer object to prevent adders and removers from being called
1 parent fd94910 commit 6048a4d

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

Form/DataTransformer/HashToKeyValueArrayTransformer.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Burgov\Bundle\KeyValueFormBundle\Form\DataTransformer;
33

4+
use Burgov\Bundle\KeyValueFormBundle\KeyValueContainer;
45
use Symfony\Component\Form\DataTransformerInterface;
56
use Symfony\Component\Form\Exception\TransformationFailedException;
67

@@ -18,7 +19,7 @@ public function transform($value)
1819

1920
public function reverseTransform($value)
2021
{
21-
$return = array();
22+
$return = new KeyValueContainer();
2223

2324
foreach ($value as $data) {
2425
if (array('key', 'value') != array_keys($data)) {

KeyValueContainer.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Burgov\Bundle\KeyValueFormBundle;
4+
5+
class KeyValueContainer implements \ArrayAccess
6+
{
7+
private $data;
8+
9+
public function __construct(array $data = array())
10+
{
11+
$this->data = $data;
12+
}
13+
14+
public function toArray()
15+
{
16+
return $this->data;
17+
}
18+
19+
public function offsetExists($offset)
20+
{
21+
return array_key_exists($offset, $this->data);
22+
}
23+
24+
public function offsetGet($offset)
25+
{
26+
return $this->data[$offset];
27+
}
28+
29+
public function offsetSet($offset, $value)
30+
{
31+
$this->data[$offset] = $value;
32+
}
33+
34+
public function offsetUnset($offset)
35+
{
36+
unset($this->data[$offset]);
37+
}
38+
}
39+

0 commit comments

Comments
 (0)