Parse and validate AT Protocol Lexicons with DTO generation for Laravel
at dev 637 B view raw
1<?php 2 3namespace SocialDept\AtpSchema\Validation\Rules; 4 5use Closure; 6use Illuminate\Contracts\Validation\ValidationRule; 7use SocialDept\AtpSchema\Parser\Nsid as NsidParser; 8 9class Nsid implements ValidationRule 10{ 11 /** 12 * Run the validation rule. 13 */ 14 public function validate(string $attribute, mixed $value, Closure $fail): void 15 { 16 if (! is_string($value)) { 17 $fail("The {$attribute} must be a string."); 18 19 return; 20 } 21 22 try { 23 NsidParser::parse($value); 24 } catch (\Exception) { 25 $fail("The {$attribute} is not a valid NSID."); 26 } 27 } 28}