/** * 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; }
public function test_it_indicates_its_path() { $path = 'foo.bar.baz'; $param = new Parameter($this->data + ['path' => $path]); $this->assertEquals($path, $param->getPath()); }