private function replace(&$json, array $pointerParts, $value = null)
{
$pointerPart = array_shift($pointerParts);
if (is_string($this->getValue())) {
$value = json_decode($this->getValue());
}
if (!is_array($value) && !is_object($value)) {
$value = $this->getValue();
}
if (is_object($json) && array_key_exists($pointerPart, get_object_vars($json))) {
if (count($pointerParts) === 0) {
$json->{$pointerPart} = $value;
} else {
$this->replace($json->{$pointerPart}, $pointerParts, $value);
}
} elseif ($pointerPart === Pointer::LAST_ARRAY_ELEMENT_CHAR && is_array($json)) {
$json[count($json) - 1] = $value;
} elseif (is_array($json) && isset($json[$pointerPart])) {
if (count($pointerParts) === 0) {
$json[$pointerPart] = $value;
} else {
$this->replace($json[$pointerPart], $pointerParts, $value);
}
}
}