/** * @param string $xrefKey * @param string|array $xrefInfo * @param XrefTokenResolverCollection $xrefTokenResolvers * @param Xref[] $xrefPath * @return Xref|mixed * @throws TreeCompilerFormatException * @throws \Exception */ protected function parseXrefInfo($xrefKey, $xrefInfo, XrefTokenResolverCollection $xrefTokenResolvers = null, $xrefPath) { $xrefData = null; if (gettype($xrefInfo) == 'string') { list($xrefType, $xrefLocation) = Xref::parseDefinitionString($xrefInfo, $this->xrefTypeAndLocationDelimiter); } else { if (!is_array($xrefInfo)) { throw new TreeCompilerFormatException(sprintf('The Xref definition key "%s" must be a string with the format xref_type %s xref_location ' . 'or an associative array with the keys "%s" for type and "%s" for location.', $this->xrefTypeAndLocationDelimiter, $this->includeXrefTypeKey, $this->includeXrefLocationKey)); } $requiredKeyErrorMessage = 'The "%s" key is missing from the Xref definition with the key "%s".'; if (!isset($xrefInfo[$this->includeXrefTypeKey])) { throw new TreeCompilerFormatException(sprintf($requiredKeyErrorMessage, $this->includeXrefTypeKey, $xrefKey)); } $xrefType = $xrefInfo[$this->includeXrefTypeKey]; if ($xrefType == InlineXrefResolver::getType()) { if (!isset($xrefInfo[$this->includeXrefDataKey])) { throw new TreeCompilerFormatException(sprintf($requiredKeyErrorMessage, $this->includeXrefDataKey, $xrefKey)); } $xrefData = $xrefInfo[$this->includeXrefDataKey]; $xrefLocation = Xref::computeId($xrefType, serialize($xrefData)); } else { if (!isset($xrefInfo[$this->includeXrefLocationKey])) { throw new TreeCompilerFormatException(sprintf($requiredKeyErrorMessage, $this->includeXrefLocationKey, $xrefKey)); } $xrefLocation = $xrefInfo[$this->includeXrefLocationKey]; } } if (isset($xrefData)) { if (isset($xrefTokenResolvers)) { $xrefTokenResolvers->applyToArray($xrefData); } } else { if (isset($xrefTokenResolvers)) { $xrefLocation = $xrefTokenResolvers->applyToString($xrefLocation); } $xrefLocation = Xref::computeAbsoluteLocation($xrefType, $xrefLocation, $xrefPath); } $xrefId = Xref::computeId($xrefType, $xrefLocation); if ($this->xrefs->hasById($xrefId)) { return $this->xrefs[$xrefId]; } $xref = new Xref($xrefType, $xrefLocation); if (isset($xrefData)) { $xref->setData($xrefData)->setResolved(true); } return $xref; }