2) { throw new \InvalidArgumentException('AT URI may include only repo, collection, and rkey components.'); } if (\in_array('', $parts, TRUE)) { throw new \InvalidArgumentException('AT URI path components may not be empty.'); } $collection = $parts[0] ?? NULL; $rkey = $parts[1] ?? NULL; $normalized_repo = $this->normalizeRepo($repo); $normalized_collection = $collection !== NULL ? $this->nsidParser->normalize($collection) : NULL; $normalized_rkey = $rkey !== NULL ? $this->recordKeyParser->normalize($rkey) : NULL; $normalized = AtUri::SCHEME_PREFIX . $normalized_repo; if ($normalized_collection !== NULL) { $normalized .= '/' . $normalized_collection; } if ($normalized_rkey !== NULL) { $normalized .= '/' . $normalized_rkey; } return new AtUri($normalized_repo, $normalized_collection, $normalized_rkey, $normalized); } /** * Builds a canonical record AT URI from its components. */ public function build(string $repo, string $collection, string $rkey): string { return \sprintf( AtUri::SCHEME_PREFIX . '%s/%s/%s', $this->normalizeRepo($repo), $this->nsidParser->normalize($collection), $this->recordKeyParser->normalize($rkey), ); } /** * Returns whether the value is a valid AT URI. */ public function isValid(string $uri): bool { try { $this->parse($uri); } catch (\InvalidArgumentException) { return FALSE; } return TRUE; } private function normalizeRepo(string $repo): string { if ($this->didParser->isValid($repo)) { return $this->didParser->normalize($repo); } return $this->handleParser->normalize($repo); } }