|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tahoe\Bundle\MultiTenancyBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
6
|
|
|
use Symfony\Component\Config\FileLocator; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* This is the class that loads and manages your bundle configuration |
|
15
|
|
|
* |
|
16
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
|
17
|
|
|
*/ |
|
18
|
|
|
class TahoeMultiTenancyExtension extends Extension |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritDoc} |
|
22
|
|
|
*/ |
|
23
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
24
|
|
|
{ |
|
25
|
|
|
$configuration = new Configuration(); |
|
26
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
27
|
|
|
|
|
28
|
|
|
$container->setParameter($this->getAlias() . ".account_prefix", $config['account_prefix']); |
|
29
|
|
|
// we load the registration subscriber config |
|
30
|
|
|
if (array_key_exists('registration_subscriber', $config)) { |
|
31
|
|
|
$this->loadRegistrationSubscriber($container, $config['registration_subscriber']); |
|
32
|
|
|
} else { |
|
33
|
|
|
// load default subscriber |
|
34
|
|
|
$this->loadRegistrationSubscriber($container, []); |
|
35
|
|
|
} |
|
36
|
|
|
// we set the subdomain strategy |
|
37
|
|
|
$container->setParameter(sprintf("%s.subdomain_strategy", $this->getAlias()), $config['subdomain_strategy']); |
|
38
|
|
|
// we load all the rest of the files |
|
39
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
40
|
|
|
$loader->load('controllers.yml'); |
|
41
|
|
|
$loader->load('factories.yml'); |
|
42
|
|
|
$loader->load('repositories.yml'); |
|
43
|
|
|
$loader->load('services.yml'); |
|
44
|
|
|
$loader->load('handlers.yml'); |
|
45
|
|
|
$loader->load('subscribers.yml'); |
|
46
|
|
|
$loader->load('forms.yml'); |
|
47
|
|
|
|
|
48
|
|
|
if (array_key_exists('gateways', $config)) { |
|
49
|
|
|
$loader->load('gateways.yml'); |
|
50
|
|
|
$this->loadGatewaysParameters($container, $config['gateways']); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private function loadRegistrationSubscriber(ContainerBuilder $container, array $config) |
|
55
|
|
|
{ |
|
56
|
|
|
$definition = new Definition(); |
|
57
|
|
|
if (array_key_exists('class', $config)) { |
|
58
|
|
|
$definition->setClass($config['class']); |
|
59
|
|
|
} else { |
|
60
|
|
|
$definition->setClass('Tahoe\Bundle\MultiTenancyBundle\EventSubscriber\RegistrationSubscriber'); |
|
61
|
|
|
} |
|
62
|
|
|
$definition->addTag('kernel.event_subscriber'); |
|
63
|
|
|
if (array_key_exists('manager', $config)) { |
|
64
|
|
|
$definition->addArgument(new Reference($config['manager'])); |
|
65
|
|
|
} else { |
|
66
|
|
|
$definition->addArgument(new Reference('tahoe.multi_tenancy.registration_manager')); |
|
67
|
|
|
} |
|
68
|
|
|
if (array_key_exists('router', $config)) { |
|
69
|
|
|
$definition->addMethodCall('setRouter', array(new Reference($config['router']))); |
|
70
|
|
|
} else { |
|
71
|
|
|
$definition->addMethodCall('setRouter', array(new Reference('tahoe.multi_tenancy.tenant_aware_router'))); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (array_key_exists('redirect_route', $config)) { |
|
75
|
|
|
$container->setParameter(sprintf("%s.registration_subscriber.redirect_route", $this->getAlias()), $config['redirect_route']); |
|
76
|
|
|
} else { |
|
77
|
|
|
// default parameter |
|
78
|
|
|
$container->setParameter(sprintf("%s.registration_subscriber.redirect_route", $this->getAlias()), 'dashboard'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
// we add the definition to the container |
|
82
|
|
|
$container->setDefinition('tahoe.multi_tenancy.registration_subscriber', $definition); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
private function loadGatewaysParameters(ContainerInterface $container, $gateways) |
|
86
|
|
|
{ |
|
87
|
|
|
foreach($gateways as $gateway => $params) { |
|
88
|
|
|
foreach($params as $key => $paramater) { |
|
89
|
|
|
$container->setParameter(sprintf("%s.%s.%s", $this->getAlias(), $gateway, $key), $paramater);; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|