/** * Resolve the items contained in other CHM files. * * @param Map $map * @param bool $ignoreErrors Set to true to ignore missing CHM and/or entries. * * @throws Exception Throw an Exception in case of errors. * * @return static[] */ public function resolve(Map $map, $ignoreErrors = false) { $result = array($this); if (is_array($this->merge)) { $chm = $map->get($this->merge['chm']); if ($chm === null) { if (!$ignoreErrors) { throw new Exception("Missing CHM reference from map: {$this->merge['chm']}"); } } else { $entry = $chm->getEntryByPath($this->merge['entry']); if ($entry === null) { if (!$ignoreErrors) { throw new Exception("Missing entry '{$this->merge['entry']}' in CHM file {$this->merge['chm']}"); } } else { $tree = Tree::fromString($chm, $entry->getContents()); $tree->resolve($map, $ignoreErrors); $result = $tree->getItems(); } } } foreach ($result as $newItem) { $newItem->children->resolve($map, $ignoreErrors); } return $result; }
/** * Get the index of this CHM file (if available). * * @return TOCIndex\Tree|null */ public function getIndex() { if ($this->index === null) { $r = false; foreach ($this->entries as $entry) { if ($entry->isFile() && strcasecmp(substr($entry->getPath(), -4), '.hhk') === 0) { $r = TOCIndex\Tree::fromString($this, $entry->getContents()); break; } } $this->index = $r; } return $this->index === false ? null : $this->index; }