isValid($repo) ? $didParser->normalize($repo) === $repo : $handleParser->isValid($repo) && $handleParser->normalize($repo) === $repo; if (!$validRepo) { throw new \InvalidArgumentException('AT URI repository must be a normalized DID or handle.'); } if ( $collection !== NULL && (!NsidParser::isValid($collection) || new NsidParser()->normalize($collection) !== $collection) ) { throw new \InvalidArgumentException('AT URI collection must be a normalized NSID.'); } if ($rkey !== NULL && ($collection === NULL || !RecordKeyParser::isValid($rkey))) { throw new \InvalidArgumentException('AT URI record key requires a collection and must be valid.'); } $expected = self::SCHEME_PREFIX . $repo; if ($collection !== NULL) { $expected .= '/' . $collection; } if ($rkey !== NULL) { $expected .= '/' . $rkey; } if ($normalized !== NULL && $normalized !== $expected) { throw new \InvalidArgumentException('Normalized AT URI does not match its components.'); } } /** * Returns the canonical string representation. */ public function __toString(): string { if ($this->normalized !== NULL) { return $this->normalized; } $uri = self::SCHEME_PREFIX . $this->repo; if ($this->collection !== NULL) { $uri .= '/' . $this->collection; } if ($this->rkey !== NULL) { $uri .= '/' . $this->rkey; } return $uri; } }