public function test_it_sets_arrays_according_to_paths() { $jsonPath = new JsonPath(['foo' => ['bar' => ['value' => 'VALUE']]]); $jsonPath->set('foo.bar.items', ['item_1', 'item_2']); $expected = ['foo' => ['bar' => ['value' => 'VALUE', 'items' => ['item_1', 'item_2']]]]; $this->assertEquals($expected, $jsonPath->getStructure()); }
/** * Populates the actual value into a JSON field, i.e. it has reached the end of the line and no * further nesting is required. * * @param Parameter $param The schema that defines how the JSON field is being populated * @param mixed $userValue The user value that is populating a JSON field * @param array $json The existing JSON structure that will be populated * * @return array|mixed */ private function stockValue(Parameter $param, $userValue, array $json) : array { $name = $param->getName(); if ($path = $param->getPath()) { $jsonPath = new JsonPath($json); $jsonPath->set(sprintf("%s.%s", $path, $name), $userValue); $json = $jsonPath->getStructure(); } elseif ($name) { $json[$name] = $userValue; } else { $json[] = $userValue; } return $json; }