use Symfony\Component\HttpFoundation\RequestMatcher\IsJsonRequestMatcher;
use Symfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;
use Symfony\Component\Webhook\Client\AbstractRequestParser;
use Symfony\Component\Webhook\Exception\RejectWebhookException;
final class VonageRequestParser extends AbstractRequestParser
{ protected function getRequestMatcher(): RequestMatcherInterface
{ return new ChainRequestMatcher([ new MethodRequestMatcher('POST'
),
new IsJsonRequestMatcher(),
]);
} protected function doParse(Request
$request, string
$secret): ?SmsEvent
{ // Signed webhooks: https://developer.vonage.com/en/getting-started/concepts/webhooks#validating-signed-webhooks
if (!
$request->headers->
has('Authorization'
)) { throw new RejectWebhookException(406, 'Missing "Authorization" header.'
);
}