1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Service; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Entity\PeopleDomain; |
|
|
|
|
6
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
8
|
|
|
use InvalidArgumentException; |
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class DomainService |
13
|
|
|
{ |
14
|
|
|
private static $peopleDomain; |
15
|
|
|
private $request; |
16
|
|
|
public function __construct( |
17
|
|
|
private EntityManagerInterface $manager, |
18
|
|
|
RequestStack $requestStack |
19
|
|
|
) { |
20
|
|
|
$this->request = $requestStack->getCurrentRequest(); |
21
|
|
|
} |
22
|
|
|
/** |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function getDomain() |
26
|
|
|
{ |
27
|
|
|
|
28
|
|
|
$domain = !$this->request ? $this->getMainDomain() : preg_replace("/[^a-zA-Z0-9.:_-]/", "", str_replace( |
29
|
|
|
['https://', 'http://'], |
30
|
|
|
'', |
31
|
|
|
$this->request->get( |
32
|
|
|
'App-domain', |
33
|
|
|
$this->request->get( |
34
|
|
|
'app-domain', |
35
|
|
|
$this->request->headers->get( |
36
|
|
|
'app-domain', |
37
|
|
|
$this->request->headers->get( |
38
|
|
|
'referer', |
39
|
|
|
$this->getMainDomain() |
40
|
|
|
) |
41
|
|
|
) |
42
|
|
|
) |
43
|
|
|
) |
44
|
|
|
)); |
45
|
|
|
|
46
|
|
|
if (!$domain) |
47
|
|
|
throw new InvalidArgumentException('Please define header or get param "app-domain"', 301); |
48
|
|
|
return $domain; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getMainDomain() |
52
|
|
|
{ |
53
|
|
|
return $this->request ? $this->request->server->get('HTTP_HOST') : 'api.controleonline.com'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getPeopleDomain(): PeopleDomain |
57
|
|
|
{ |
58
|
|
|
if (self::$peopleDomain) return self::$peopleDomain; |
59
|
|
|
|
60
|
|
|
$domain = $this->getDomain(); |
61
|
|
|
self::$peopleDomain = $this->manager->getRepository(PeopleDomain::class)->findOneBy(['domain' => $domain]); |
62
|
|
|
|
63
|
|
|
if (!self::$peopleDomain) { |
64
|
|
|
$domain = $this->getMainDomain(); |
65
|
|
|
self::$peopleDomain = $this->manager->getRepository(PeopleDomain::class)->findOneBy(['domain' => $domain]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if (self::$peopleDomain === null) |
69
|
|
|
throw new \Exception( |
70
|
|
|
sprintf('Main company "%s" not found', $domain) |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return self::$peopleDomain; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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