This repository was archived by the owner on Jan 6, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSinchController.php
More file actions
69 lines (60 loc) · 2 KB
/
SinchController.php
File metadata and controls
69 lines (60 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
* This file is part of the FreshSinchBundle
*
* (c) Artem Henvald <genvaldartem@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Fresh\SinchBundle\Controller;
use Fresh\SinchBundle\Event\SmsMessageCallbackEvent;
use Fresh\SinchBundle\Form\Type\CallbackRequestType;
use Fresh\SinchBundle\Model\CallbackRequest;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* SinchController.
*
* @author Artem Henvald <genvaldartem@gmail.com>
*/
class SinchController
{
/** @var EventDispatcherInterface */
private $eventDispatcher;
/** @var FormFactory */
private $formFactory;
/**
* @param FormFactory $formFactory
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(FormFactory $formFactory, EventDispatcherInterface $eventDispatcher)
{
$this->formFactory = $formFactory;
$this->eventDispatcher = $eventDispatcher;
}
/**
* @param Request $request
*
* @return Response
*/
public function callbackAction(Request $request): Response
{
try {
$callbackRequest = new CallbackRequest();
$form = $this->formFactory->create(CallbackRequestType::class, $callbackRequest);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->eventDispatcher->dispatch(new SmsMessageCallbackEvent($callbackRequest));
} else {
return new Response('Bad Request', Response::HTTP_BAD_REQUEST);
}
} catch (\Exception $e) {
return new Response('Internal Server Error', Response::HTTP_INTERNAL_SERVER_ERROR);
}
return new Response(null, Response::HTTP_OK);
}
}