Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Identifier;
/** * Value object for a parsed DID. * * @api */final readonly class Did {
public function __construct( public string $value, public string $method, public string $identifier, public bool $supported, ) { if (!DidParser::isValid($value)) { throw new \InvalidArgumentException(\sprintf('Invalid DID "%s".', $value)); } [, $parsedMethod, $parsedIdentifier] = \explode(':', $value, 3); $expectedSupported = \in_array($parsedMethod, ['plc', 'web'], TRUE); if ($method !== $parsedMethod || $identifier !== $parsedIdentifier || $supported !== $expectedSupported) { throw new \InvalidArgumentException('DID components do not match the parsed value.'); } }
/** * Returns the canonical string representation. */ public function __toString(): string { return $this->value; }
}