-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParkManagerCoreModule.php
66 lines (53 loc) · 3.01 KB
/
ParkManagerCoreModule.php
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
<?php
declare(strict_types=1);
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace ParkManager\Module\CoreModule;
use ParkManager\Module\CoreModule\Infrastructure\DependencyInjection\DependencyExtension;
use ParkManager\Module\CoreModule\Infrastructure\DependencyInjection\EnvVariableResource;
use ParkManager\Module\CoreModule\Infrastructure\DependencyInjection\Module\AbstractParkManagerModule;
use ParkManager\Module\CoreModule\Infrastructure\Http\CookiesRequestMatcher;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpFoundation\RequestMatcher;
use function realpath;
class ParkManagerCoreModule extends AbstractParkManagerModule
{
public function getContainerExtension(): ?ExtensionInterface
{
if ($this->extension === null) {
$this->extension = new DependencyExtension();
}
return $this->extension;
}
public static function setAppConfiguration(ContainerBuilder $container): void
{
$container->addResource(new EnvVariableResource('PRIMARY_HOST'));
$container->addResource(new EnvVariableResource('ENABLE_HTTPS'));
$isSecure = (($_ENV['ENABLE_HTTPS'] ?? 'false') === 'true');
$primaryHost = $_ENV['PRIMARY_HOST'] ?? null;
$container->setParameter('park_manager.config.primary_host', $_ENV['PRIMARY_HOST'] ?? '');
$container->setParameter('park_manager.config.requires_channel', $isSecure ? 'https' : null);
$container->setParameter('park_manager.config.is_secure', $isSecure);
$container->register('park_manager.section.admin.request_matcher', RequestMatcher::class)->setArguments(['^/admin/']);
$container->register('park_manager.section.client.request_matcher', RequestMatcher::class)->setArguments(['^/(?!(api|admin)/)']);
$container->register('park_manager.section.api.request_matcher', RequestMatcher::class)->setArguments(['/api']);
$container->register('park_manager.section.private.request_matcher', CookiesRequestMatcher::class)
->setArguments(['^/(?!(api|admin)/)'])
->addMethodCall('matchCookies', [['_private_section' => '^true$']]);
if ($primaryHost !== null) {
$container->getDefinition('park_manager.section.admin.request_matcher')->setArgument(1, $primaryHost);
$container->getDefinition('park_manager.section.private.request_matcher')->setArgument(1, $primaryHost);
$container->getDefinition('park_manager.section.api.request_matcher')->setArguments(['/', '^api\.']);
}
}
protected function getDoctrineOrmMappings(): array
{
$mapping = parent::getDoctrineOrmMappings();
$mapping[realpath(__DIR__ . '/Infrastructure/Doctrine/SecurityMapping')] = 'Rollerworks\\Component\\SplitToken';
return $mapping;
}
}