function clone_object($object) { $values = get_values($object); return build_object(get_class($object), $values); }
/** * @internal * * @param string $namespace * @param string $key * @param string|\Closure $classOrClosure * * @return object[] */ protected function getObjects($namespace, $key, $classOrClosure) { if (false == isset($this->values[$namespace][$key])) { return []; } if (false == isset($this->objects[$namespace][$key])) { $this->objects[$namespace][$key] = []; } // the addObject method can add an object to the end of collection but the rest of collection has not been initiated yet foreach (array_keys($this->values[$namespace][$key]) as $valueKey) { if (false == isset($this->objects[$namespace][$key][$valueKey])) { $this->objects[$namespace][$key][$valueKey] = build_object($classOrClosure, $this->values[$namespace][$key][$valueKey], $this->objectBuilder); } } return $this->objects[$namespace][$key]; }
/** * @param string $key * @param string|\Closure $classOrClosure * * @return \Traversable */ protected function getObjects($key, $classOrClosure) { foreach (array_keys(get_value($key, [], $this->values)) as $valueKey) { if (false == ($object = get_value("{$key}.{$valueKey}", null, $this->objects))) { $values =& get_value("{$key}.{$valueKey}", [], $this->values); $object = build_object($classOrClosure, $values, $this->objectBuilder); set_value($key, $object, $this->objects); } (yield $object); } }