1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Fluxter\SaasProviderBundle\EventSubscriber;
|
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
6
|
|
|
use Fluxter\SaasProviderBundle\Model\SaasClientUserInterface;
|
7
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
8
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
9
|
|
|
use Symfony\Component\HttpKernel\Event\KernelEvent;
|
10
|
|
|
use Symfony\Component\HttpKernel\KernelEvents;
|
11
|
|
|
use Fluxter\SaasProviderBundle\Service\SaasClientService;
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
13
|
|
|
|
14
|
|
|
class ClientSubscriber implements EventSubscriberInterface
|
15
|
|
|
{
|
16
|
|
|
/** @var EntityManagerInterface */
|
17
|
|
|
private $em;
|
18
|
|
|
|
19
|
|
|
/** @var SessionInterface */
|
20
|
|
|
private $session;
|
21
|
|
|
|
22
|
|
|
/** @var SaasClientService */
|
23
|
|
|
private $clientService;
|
24
|
|
|
|
25
|
|
|
public function __construct(EntityManagerInterface $em, SessionInterface $session, SaasClientService $clientService)
|
26
|
|
|
{
|
27
|
|
|
$this->em = $em;
|
28
|
|
|
$this->session = $session;
|
29
|
|
|
$this->clientService = $clientService;
|
30
|
|
|
}
|
31
|
|
|
|
32
|
|
|
public static function getSubscribedEvents()
|
33
|
|
|
{
|
34
|
|
|
$events = [
|
35
|
|
|
KernelEvents::REQUEST => ['checkSaasClient', 101],
|
36
|
|
|
];
|
37
|
|
|
|
38
|
|
|
if (class_exists("FOS\UserBundle\FOSUserEvents")) {
|
39
|
|
|
$events[\FOS\UserBundle\FOSUserEvents::REGISTRATION_SUCCESS] = 'addSaasClientAfterSuccessfullRegistration';
|
|
|
|
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
return $events;
|
43
|
|
|
}
|
44
|
|
|
|
45
|
|
|
/**
|
46
|
|
|
* Add the correct client after successfull registration
|
47
|
|
|
*
|
48
|
|
|
* @param \FOS\UserBundle\Event\FormEvent $event
|
|
|
|
|
49
|
|
|
* @return void
|
50
|
|
|
*/
|
51
|
|
|
public function addSaasClientAfterSuccessfullRegistration($event)
|
52
|
|
|
{
|
53
|
|
|
/** @var SaasClientUserInterface $user */
|
54
|
|
|
$user = $event->getForm()->getData();
|
55
|
|
|
|
56
|
|
|
// Todo get the default role by the saasclient
|
57
|
|
|
$defaultRole = null;
|
58
|
|
|
$client = $this->clientService->getCurrentClient();
|
59
|
|
|
|
60
|
|
|
$user->addRole($client, $defaultRole);
|
|
|
|
|
61
|
|
|
}
|
62
|
|
|
|
63
|
|
|
/**
|
64
|
|
|
* Discovers and checks if the current saas client exists by the current domain
|
65
|
|
|
* and sets the session variables and updates them if needed.
|
66
|
|
|
*
|
67
|
|
|
* @param KernelEvent $event
|
68
|
|
|
* @return void
|
69
|
|
|
*/
|
70
|
|
|
public function checkSaasClient(KernelEvent $event)
|
71
|
|
|
{
|
72
|
|
|
$current = $this->clientService->getCurrentClient();
|
73
|
|
|
if ($current == null) {
|
74
|
|
|
$event->setResponse(new Response('Not found!', 404));
|
|
|
|
|
75
|
|
|
return;
|
76
|
|
|
}
|
77
|
|
|
}
|
78
|
|
|
}
|
79
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths