pointer = $pointer; $this->each = $each; $this->hasDefault = func_num_args() === 3; $this->defaultValue = $default; } /** * @return JsonPointer */ public function pointer(): JsonPointer { return $this->pointer; } /** * @return null|Variables */ public function each(): ?Variables { return $this->each; } /** * @return bool */ public function hasDefaultValue(): bool { return $this->hasDefault; } /** * @return mixed|null */ public function defaultValue() { return $this->defaultValue; } /** * @inheritDoc */ public function resolve($data, array $path = []) { $resolved = $this->pointer->data($data, $path, $this); if ($resolved === $this) { return $this->defaultValue; } if ($this->each && (is_array($resolved) || is_object($resolved))) { $path = $this->pointer->absolutePath($path); foreach ($resolved as $key => &$value) { $path[] = $key; $value = $this->each->resolve($data, $path); array_pop($path); unset($value); } } return $resolved; } }