Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Lexicon\Schema;
use Wotnak\Atproto\Lexicon\SchemaCompiler;use Wotnak\Atproto\Lexicon\ValidationContext;
/** * Validates values through another Lexicon definition. * * @api */final class RefSchema extends AbstractSchema implements DefaultValueSchemaInterface {
private bool $resolvingDefault = FALSE;
public function __construct( private readonly SchemaCompiler $compiler, private readonly string $ref, private readonly string $baseNsid, ) {}
/** * Validates the value. */ public function validateValue(mixed $value, ValidationContext $context): mixed { $schema = $this->compiler->compileRef($this->ref, $this->baseNsid); if (!$schema instanceof SchemaInterface) { $context->addViolation(\sprintf('Unable to resolve lexicon ref "%s".', $this->ref), 'unresolved_ref'); return $value; } return $schema->validateValue($value, $context); }
/** * Returns the default value declared by the schema. */ public function defaultValue(): bool|int|string|null { if ($this->resolvingDefault) { return NULL; }
$this->resolvingDefault = TRUE; try { $schema = $this->compiler->compileRef($this->ref, $this->baseNsid); return $schema instanceof DefaultValueSchemaInterface ? $schema->defaultValue() : NULL; } finally { $this->resolvingDefault = FALSE; } }
}