<?php
namespace App\Application\Services\Webhooks;
use DomainException;
final class WebhookDestinationValidator {
 public function validate(string $url,bool $live=true):array{$p=parse_url($url);if(!$p||empty($p['host']))throw new DomainException('Invalid webhook URL.');if($live&&strtolower($p['scheme']??'')!=='https')throw new DomainException('Live webhooks require HTTPS.');$ips=gethostbynamel($p['host'])?:[];if(!$ips)throw new DomainException('Webhook host could not be resolved.');foreach($ips as $ip){if(!filter_var($ip,FILTER_VALIDATE_IP,FILTER_FLAG_NO_PRIV_RANGE|FILTER_FLAG_NO_RES_RANGE))throw new DomainException('Webhook destination resolves to a private, loopback, metadata, reserved, or link-local address.');}return $ips;}
}
