path = $path; } /** * {@inheritDoc} * * @param mixed[string] $values * The array of values. * @param mixed $value * The value to inject. * * @return mixed[string] * The resulting array of values. * * @throws \Exception * Thrown if the path is empty. * * @since 2.4.0 */ public function inject(array $values, $value) { if (empty($this->path)) { throw new \Exception('A hierarchical injector path cannot be empty'); } $keys = array_reverse($this->path); $key = array_shift($keys); $root = [ $key => $value, ]; foreach ($keys as $key) { $root = [ $key => $root, ]; } return array_replace_recursive($values, $root); } }