parser = $parser; } /** * Override without type check. * * @return ExternalFeedObjectWrapper */ public function setObject($object) { $this->object = $object; return $this; } public function setFeedRow(array $feedRow) { $this->feedRow = $feedRow; $this->serialize(); } private function serialize(): void { $cache = new ExternalFeedCache($this->feedRow); $this->parser->loadFile($cache->getDescriptionUrl()); $this->serialized = $this->prepareForPrint( $this->parser->getFeedRootElement()->serialize() ); $this->serialized['__search'] = ''; } private function prepareForPrint(array $array): array { $flattened = []; foreach ($array['children'] ?? [] as $child) { if (!empty($child['children'])) { $flattened[$child['name']] = $this->prepareForPrint($child); } else { $flattened[$child['name']] = ''; } } return $flattened; } public function offsetExists($offset): bool { return isset($this->object[$offset]); } public function offsetGet($offset): mixed { return $this->object[$offset] ?? null; } public function offsetSet($offset, $value): void { $this->object[$offset] = $value; } public function offsetUnset($offset): void { unset($this->object[$offset]); } /** * Loads field names into JS global context. */ public function getFieldsAndMethodsNames(): array { return array_keys($this->serialized); } public function getRawFieldsAndMethods(): array { return array_map(fn ($f) => ['name' => $f, 'method' => false], $this->getFieldsAndMethodsNames()); } public function getFieldsAndMethods(): array { return []; } }