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.'
);
} $this->
validateSignature(substr($request->headers->
get('Authorization'
), \
strlen('Bearer '
)),
$secret);