Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Lexicon\Schema;
use Wotnak\Atproto\Lexicon\ValidationContext;
/** * A named Lexicon token that acts as both a schema and its string value. * * @api */final class TokenSchema extends AbstractSchema implements \JsonSerializable, \Stringable {
public function __construct( public readonly string $value, ) {}
/** * Validates the value. */ public function validateValue(mixed $value, ValidationContext $context): mixed { if ($value === $this->value) { return $this->value; } if ( $context->options->mode === 'parse' && $value instanceof self && $value->value === $this->value ) { return $this->value; } if (!\is_string($value)) { $context->addViolation('Expected token string.', 'invalid_type'); return $value; } $context->addViolation(\sprintf('Expected token "%s".', $this->value), 'invalid_token'); return $value; }
/** * Returns the JSON-serializable representation. */ public function jsonSerialize(): string { return $this->value; }
/** * Returns the canonical string representation. */ public function __toString(): string { return $this->value; }
}