1 | <?php |
||
33 | class SurfnetStepupExtension extends Extension |
||
34 | { |
||
35 | public function load(array $config, ContainerBuilder $container) |
||
36 | { |
||
37 | $processor = new Processor(); |
||
38 | $config = $processor->processConfiguration(new Configuration(), $config); |
||
39 | |||
40 | $container->setParameter('logging.application_name', $config['logging']['application_name']); |
||
41 | |||
42 | $loader = new YamlFileLoader( |
||
43 | $container, |
||
44 | new FileLocator(__DIR__ . '/../Resources/config') |
||
45 | ); |
||
46 | $loader->load('services.yml'); |
||
47 | |||
48 | if (isset($config['loa_definition']) && $config['loa_definition']['enabled']) { |
||
49 | $this->defineLoas($config['loa_definition'], $container); |
||
50 | } else { |
||
51 | $container->removeDefinition('surfnet_stepup.service.loa_resolution'); |
||
52 | } |
||
53 | |||
54 | if ($config['sms']['enabled'] === false) { |
||
55 | $container->removeDefinition('surfnet_stepup.service.sms_second_factor'); |
||
56 | $container->removeDefinition('surfnet_stepup.service.challenge_handler'); |
||
57 | $container->removeDefinition('surfnet_stepup.service.sms_second_factor'); |
||
58 | } else { |
||
59 | $this->configureSmsSecondFactorServices($config, $container); |
||
60 | |||
61 | if (!$config['gateway_api']['enabled'] && $config['sms']['service'] === Configuration::DEFAULT_SMS_SERVICE) { |
||
|
|||
62 | throw new RuntimeException( |
||
63 | 'The gateway API is not enabled and no replacement SMS service is configured' |
||
64 | ); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | if ($config['gateway_api']['enabled']) { |
||
69 | $this->configureGatewayApiClient($config, $container); |
||
70 | } else { |
||
71 | // Remove the Gateway API SMS service and its Guzzle client. |
||
72 | $container->removeDefinition('surfnet_stepup.service.gateway_api_sms'); |
||
73 | $container->removeDefinition('surfnet_stepup.guzzle.gateway_api'); |
||
74 | } |
||
75 | |||
76 | if ($config['locale_cookie']['enabled']) { |
||
77 | $this->configureLocaleCookieSettings($config, $container); |
||
78 | } else { |
||
79 | $container->removeDefinition('surfnet_stepup.locale_cookie_helper'); |
||
80 | $container->removeDefinition('surfnet_stepup.locale_cookie_settings'); |
||
81 | } |
||
82 | |||
83 | $this->configureLocaleSelectionWidget($config, $container); |
||
84 | $this->configureSecondFactorTypeService($config, $container); |
||
85 | } |
||
86 | |||
87 | private function defineLoas(array $loaDefinitions, ContainerBuilder $container) |
||
97 | |||
98 | /** |
||
99 | * @param array $config |
||
100 | * @param ContainerBuilder $container |
||
101 | */ |
||
102 | private function configureLocaleCookieSettings(array $config, ContainerBuilder $container) |
||
117 | |||
118 | /** |
||
119 | * @param array $config |
||
120 | * @param ContainerBuilder $container |
||
121 | */ |
||
122 | private function configureGatewayApiClient(array $config, ContainerBuilder $container) |
||
144 | |||
145 | /** |
||
146 | * @param array $config |
||
147 | * @param ContainerBuilder $container |
||
148 | */ |
||
149 | private function configureSmsSecondFactorServices(array $config, ContainerBuilder $container) |
||
163 | |||
164 | private function configureLocaleSelectionWidget(array $loaDefinitions, ContainerBuilder $container) |
||
174 | |||
175 | private function configureSecondFactorTypeService(array $loaDefinitions, ContainerBuilder $container) |
||
181 | } |
||
182 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.