Rs\Json\Patch\Operations\Replace::replace PHP Method

replace() private method

private replace ( array | stdClass &$json, array $pointerParts, mixed $value = null )
$json array | stdClass The json_decode'd Json structure.
$pointerParts array The parts of the fed pointer.
$value mixed The value to replace.
    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);
            }
        }
    }