Something went wrong. Try again.
Parse and validate AT Protocol Lexicons with DTO generation for Laravel
Something went wrong. Try again.
1.1 kB · 51 lines
PHP
at dev
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152<?php
namespace SocialDept\AtpSchema\Data\Types;
use SocialDept\AtpSchema\Data\TypeDefinition;use SocialDept\AtpSchema\Exceptions\RecordValidationException;
class NullType extends TypeDefinition{ /** * Create a new NullType. */ public function __construct(?string $description = null) { parent::__construct('null', $description); }
/** * Create from array data. */ public static function fromArray(array $data): self { return new self( description: $data['description'] ?? null ); }
/** * Convert to array. */ public function toArray(): array { $array = ['type' => $this->type];
if ($this->description !== null) { $array['description'] = $this->description; }
return $array; }
/** * Validate a value against this type definition. */ public function validate(mixed $value, string $path = ''): void { if ($value !== null) { throw RecordValidationException::invalidType($path, 'null', gettype($value)); } }}