Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/templates/objectSetJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function set<?php echo ucfirst($columnName) ?>(array $data = array())
* @param string $path path to change or append
* @param string $data data to set
*
* @return The current object (for fluent API support)
* @return Current object (for fluent API support)
*/
public function set<?php echo ucfirst($columnName) ?>Path($path, $data)
{
Expand All @@ -43,3 +43,34 @@ public function set<?php echo ucfirst($columnName) ?>Path($path, $data)
$this->set<?php echo ucfirst($columnName) ?>($this-><?php echo $columnName ?>AsArray);
return $this;
}

/**
* Append partial of a json
*
* @param string $path path to change or append
* @param string $data data to set
*
* @return Current object (for fluent API support)
*/
public function append<?php echo ucfirst($columnName) ?>Path($path, $data)
{
if (!$this-><?php echo $columnName ?>AsArray || !is_array($this-><?php echo $columnName ?>AsArray)) {
$this->initJsonFields();
}

$pathArray = explode('.', $path);
$current = &$this-><?php echo $columnName ?>AsArray;
while ($p = array_shift($pathArray)) {
if (is_array($current) && array_key_exists($p, $current)) {
$current = &$current[$p];
} elseif (!is_array($current)) {
throw new PropelException("Can not set $path in this json");
} else {
$current[$p] = array();
$current = &$current[$p];
}
}
$current[] = $data;
$this->set<?php echo ucfirst($columnName) ?>($this-><?php echo $columnName ?>AsArray);
return $this;
}