Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 4
Metric Value
c 5
b 1
f 4
dl 0
loc 44
rs 8.8571
cc 1
eloc 37
nc 1
nop 0
1
<?php
2
3
namespace Tahoe\Bundle\MultiTenancyBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
use Tahoe\Bundle\MultiTenancyBundle\Service\TenantResolver;
8
9
/**
10
 * This is the class that validates and merges configuration from your app/config files
11
 *
12
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
13
 */
14
class Configuration implements ConfigurationInterface
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19
    public function getConfigTreeBuilder()
20
    {
21
        $treeBuilder = new TreeBuilder();
22
        $rootNode = $treeBuilder->root('tahoe_multi_tenancy');
23
24
        $supportedStrategies = [
25
            TenantResolver::STRATEGY_TENANT_AWARE_SUBDOMAIN,
26
            TenantResolver::STRATEGY_FIXED_SUBDOMAIN
27
        ];
28
29
        $rootNode
30
            ->children()
31
                ->scalarNode('subdomain_strategy')
32
                    ->isRequired()
33
                    ->validate()
34
                        ->ifNotInArray($supportedStrategies)
35
                        ->thenInvalid('The subdomain %s is not supported. Please provide one of ' . json_encode($supportedStrategies))
36
                    ->end()
37
                ->end()
38
                ->scalarNode('account_prefix')->isRequired()->cannotBeEmpty()->end()
39
                ->arrayNode('registration_subscriber')
40
                    ->children()
41
                        ->scalarNode('class')->cannotBeEmpty()->defaultValue('Tahoe\Bundle\MultiTenancyBundle\EventSubscriber\RegistrationSubscriber')->end()
42
                        ->scalarNode('manager')->end()
43
                        ->scalarNode('router')->end()
44
                        ->scalarNode('redirect_route')->end()
45
                    ->end()
46
                ->end()
47
//                ->scalarNode('registration_subscriber')->cannotBeEmpty()->end()
48
                ->arrayNode('gateways')
49
                    ->children()
50
                        ->arrayNode('recurly')
51
                            ->children()
52
                                ->scalarNode('subdomain')->isRequired()->cannotBeEmpty()->end()
53
                                ->scalarNode('private_key')->isRequired()->cannotBeEmpty()->end()
54
                                ->scalarNode('plan_name')->isRequired()->cannotBeEmpty()->end()
55
                            ->end()
56
                        ->end()
57
                    ->end()
58
                ->end()
59
            ->end();
60
61
        return $treeBuilder;
62
    }
63
}
64