@@ -19,7 +19,7 @@ public function set<?php echo ucfirst($columnName) ?>(array $data = array())
19
19
* @param string $path path to change or append
20
20
* @param string $data data to set
21
21
*
22
- * @return The current object (for fluent API support)
22
+ * @return Current object (for fluent API support)
23
23
*/
24
24
public function set<?php echo ucfirst ($ columnName ) ?> Path($path, $data)
25
25
{
@@ -43,3 +43,34 @@ public function set<?php echo ucfirst($columnName) ?>Path($path, $data)
43
43
$this->set<?php echo ucfirst ($ columnName ) ?> ($this-><?php echo $ columnName ?> AsArray);
44
44
return $this;
45
45
}
46
+
47
+ /**
48
+ * Append partial of a json
49
+ *
50
+ * @param string $path path to change or append
51
+ * @param string $data data to set
52
+ *
53
+ * @return Current object (for fluent API support)
54
+ */
55
+ public function append<?php echo ucfirst ($ columnName ) ?> Path($path, $data)
56
+ {
57
+ if (!$this-><?php echo $ columnName ?> AsArray || !is_array($this-><?php echo $ columnName ?> AsArray)) {
58
+ $this->initJsonFields();
59
+ }
60
+
61
+ $pathArray = explode('.', $path);
62
+ $current = &$this-><?php echo $ columnName ?> AsArray;
63
+ while ($p = array_shift($pathArray)) {
64
+ if (is_array($current) && array_key_exists($p, $current)) {
65
+ $current = &$current[$p];
66
+ } elseif (!is_array($current)) {
67
+ throw new PropelException("Can not set $path in this json");
68
+ } else {
69
+ $current[$p] = array();
70
+ $current = &$current[$p];
71
+ }
72
+ }
73
+ $current[] = $data;
74
+ $this->set<?php echo ucfirst ($ columnName ) ?> ($this-><?php echo $ columnName ?> AsArray);
75
+ return $this;
76
+ }
0 commit comments