1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the SaasProviderBundle package. |
5
|
|
|
* (c) Fluxter <http://fluxter.net/> |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Fluxter\SaasProviderBundle\EventSubscriber; |
11
|
|
|
|
12
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
13
|
|
|
use Fluxter\SaasProviderBundle\Model\SaasClientUserInterface; |
14
|
|
|
use Fluxter\SaasProviderBundle\Service\DynamicSaasClientAccessorService; |
15
|
|
|
use Fluxter\SaasProviderBundle\Service\SaasClientService; |
16
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
19
|
|
|
use Symfony\Component\HttpKernel\Event\KernelEvent; |
20
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
21
|
|
|
use Twig\Environment as TwigEnvironment; |
|
|
|
|
22
|
|
|
|
23
|
|
|
class ClientSubscriber implements EventSubscriberInterface |
24
|
|
|
{ |
25
|
|
|
/** @var EntityManagerInterface */ |
26
|
|
|
private $em; |
27
|
|
|
|
28
|
|
|
/** @var SessionInterface */ |
29
|
|
|
private $session; |
30
|
|
|
|
31
|
|
|
/** @var SaasClientService */ |
32
|
|
|
private $clientService; |
33
|
|
|
|
34
|
|
|
/** @var TwigEnvironment */ |
35
|
|
|
private $twig; |
36
|
|
|
|
37
|
|
|
/** @var DynamicSaasClientAccessorService */ |
38
|
|
|
private $dynamicSaasClientAccessorService; |
39
|
|
|
|
40
|
|
|
public function __construct( |
41
|
|
|
EntityManagerInterface $em, |
42
|
|
|
SessionInterface $session, |
43
|
|
|
SaasClientService $clientService, |
44
|
|
|
TwigEnvironment $twig, |
45
|
|
|
DynamicSaasClientAccessorService $dynamicSaasClientAccessorService) |
46
|
|
|
{ |
47
|
|
|
$this->em = $em; |
48
|
|
|
$this->session = $session; |
49
|
|
|
$this->clientService = $clientService; |
50
|
|
|
$this->twig = $twig; |
51
|
|
|
$this->dynamicSaasClientAccessorService = $dynamicSaasClientAccessorService; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function getSubscribedEvents() |
55
|
|
|
{ |
56
|
|
|
$events = [ |
57
|
|
|
KernelEvents::REQUEST => ['checkSaasClient', 101], |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
return $events; |
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
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
|
public function checkSaasClient(KernelEvent $event) |
70
|
|
|
{ |
71
|
|
|
$client = $this->clientService->tryGetCurrentClient(); |
72
|
|
|
if (null == $client) { |
73
|
|
|
$event->setResponse(new Response('Not found!', 404)); |
|
|
|
|
74
|
|
|
|
75
|
|
|
return; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->twig->addGlobal('saas_client_object', $client); |
79
|
|
|
$this->twig->addGlobal('saas_client', $this->dynamicSaasClientAccessorService); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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