<?php
namespace App\Controller;
use App\Entity\Sms;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class SmsController extends AbstractController {
private ObjectManager $em;
private LoggerInterface $logger;
public function __construct(ManagerRegistry $managerRegistry, LoggerInterface $logger){
$this->em = $managerRegistry->getManager();
$this->logger = $logger;
}
#[Route('/sms/callback', name: 'app_sms_smscallback')]
function smsCallback(Request $request): Response
{
$messageId = $request->get('id');
$status = $request->get('status');
if($messageId){
$sms = $this->em->getRepository(Sms::class)->findOneBy([
'messageId' => $messageId
]);
$sms->setStatus($status);
$this->em->flush();
}
return new Response('OK', Response::HTTP_OK);
}
#[Route('/sms/send_unsent', name: 'app_sms_smscallback_')]
function smsUnsent(Request $request): Response
{
return new Response('OK', Response::HTTP_OK);
}
}