forked from Codeception/symfony-module-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistrationController.php
More file actions
50 lines (39 loc) · 1.45 KB
/
RegistrationController.php
File metadata and controls
50 lines (39 loc) · 1.45 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
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Entity\User;
use App\Event\UserRegisteredEvent;
use App\Form\RegistrationFormType;
use App\Repository\Model\UserRepositoryInterface;
use App\Utils\Mailer;
use App\Utils\Notifier;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class RegistrationController extends AbstractController
{
public function __construct(
private readonly Mailer $mailer,
private readonly Notifier $notifier,
private readonly UserRepositoryInterface $userRepository,
private readonly EventDispatcherInterface $eventDispatcher,
) {
}
public function __invoke(Request $request): Response
{
$user = new User();
$form = $this->createForm(RegistrationFormType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->userRepository->save($user);
$this->mailer->sendConfirmationEmail($user);
$this->notifier->sendConfirmationNotification($user);
$this->eventDispatcher->dispatch(new UserRegisteredEvent());
return $this->redirectToRoute('app_login');
}
return $this->render('security/register.html.twig', [
'registrationForm' => $form,
]);
}
}