private function mergeReference($scope, $ref) { if (Utils::isAbsoluteUri($ref)) { return $ref; } $joinedScope = implode('', $scope); $isScopeAbsolute = Utils::isAbsoluteUri($joinedScope); $isScopeRelative = Utils::isRelativeUri($joinedScope); $isRefRelative = Utils::isRelativeUri($ref); if ($isScopeAbsolute && $isRefRelative) { $toRemove = preg_match('/\\/[^\\/]*$/', $joinedScope, $matches, PREG_OFFSET_CAPTURE); if ($toRemove === 1) { list(, $index) = $matches[0]; $joinedScope = substr($joinedScope, 0, $index + 1); } } else { if ($isScopeRelative && $isRefRelative) { $joinedScope = ""; } else { $toRemove = preg_match('/[^#\\/]+$/', $joinedScope, $matches, PREG_OFFSET_CAPTURE); if ($toRemove === 1) { list(, $index) = $matches[0]; $joinedScope = substr($joinedScope, 0, $index + 1); } } } return preg_replace('/##/', '#', $joinedScope . $ref); }