Something went wrong. Try again.
Parse and validate AT Protocol Lexicons with DTO generation for Laravel
Something went wrong. Try again.
637 B · 28 lines
PHP
at dev
1234567891011121314151617181920212223242526272829<?php
namespace SocialDept\AtpSchema\Validation\Rules;
use Closure;use Illuminate\Contracts\Validation\ValidationRule;use SocialDept\AtpSchema\Parser\Nsid as NsidParser;
class Nsid implements ValidationRule{ /** * Run the validation rule. */ public function validate(string $attribute, mixed $value, Closure $fail): void { if (! is_string($value)) { $fail("The {$attribute} must be a string.");
return; }
try { NsidParser::parse($value); } catch (\Exception) { $fail("The {$attribute} is not a valid NSID."); } }}