public function getHrefForAtomRef(DivinerAtomRef $ref) { $depth = 1; $atom = $this->peekAtomStack(); if ($atom) { $depth = $this->getAtomHrefDepth($atom); } $href = str_repeat('../', $depth); $book = $ref->getBook(); $type = $ref->getType(); $name = $ref->getName(); $context = $ref->getContext(); $href .= $book . '/' . $type . '/'; if ($context !== null) { $href .= $context . '/'; } $href .= $name . '/index.html'; return $href; }
public function findAtomByRef(DivinerAtomRef $ref) { if ($ref->getBook() != $this->getConfig('name')) { return null; } if ($this->atomNameMap === null) { $name_map = array(); foreach ($this->getPublishCache()->getIndex() as $hash => $dict) { $name_map[$dict['name']][$hash] = $dict; } $this->atomNameMap = $name_map; } $name = $ref->getName(); if (empty($this->atomNameMap[$name])) { return null; } $candidates = $this->atomNameMap[$name]; foreach ($candidates as $key => $dict) { $candidates[$key] = DivinerAtomRef::newFromDictionary($dict); if ($ref->getType()) { if ($candidates[$key]->getType() != $ref->getType()) { unset($candidates[$key]); } } if ($ref->getContext()) { if ($candidates[$key]->getContext() != $ref->getContext()) { unset($candidates[$key]); } } } // If we have exactly one uniquely identifiable atom, return it. if (count($candidates) == 1) { return $this->getAtomFromNodeHash(last_key($candidates)); } return null; }