|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2015 SURFnet B.V. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace OpenConext\ProfileBundle\DependencyInjection; |
|
20
|
|
|
|
|
21
|
|
|
use OpenConext\Profile\Value\AttributeAggregation\AttributeAggregationEnabledAttributes; |
|
22
|
|
|
use OpenConext\Profile\Value\Locale; |
|
23
|
|
|
use OpenConext\Profile\Value\LocaleSet; |
|
24
|
|
|
use OpenConext\ProfileBundle\Service\UserService; |
|
25
|
|
|
use OpenConext\ProfileBundle\Storage\SingleCookieStorage; |
|
26
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
27
|
|
|
use Symfony\Component\Config\FileLocator; |
|
28
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
29
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
30
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
31
|
|
|
use \DateTime; |
|
32
|
|
|
|
|
33
|
|
|
class OpenConextProfileExtension extends Extension |
|
34
|
|
|
{ |
|
35
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
36
|
|
|
{ |
|
37
|
|
|
$configuration = new Configuration(); |
|
38
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
39
|
|
|
|
|
40
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
41
|
|
|
$loader->load('services.yml'); |
|
42
|
|
|
|
|
43
|
|
|
$this->parseEngineBlockEntityIdConfiguration($config['engine_block_entity_id'], $container); |
|
44
|
|
|
|
|
45
|
|
|
$this->parseAttributeSupportMailConfiguration($config['attribute_support'], $container); |
|
46
|
|
|
$this->parseInformationRequestMailConfiguration($config['information_request'], $container); |
|
47
|
|
|
|
|
48
|
|
|
$this->parseDefaultLocaleConfiguration($config['default_locale'], $container); |
|
49
|
|
|
$this->parseAvailableLocaleConfiguration($config['locales'], $container); |
|
50
|
|
|
$this->parseLocaleCookieStorageConfiguration( |
|
51
|
|
|
$config['locale_cookie_domain'], |
|
52
|
|
|
$config['locale_cookie_key'], |
|
53
|
|
|
$config['locale_cookie_expires_in'], |
|
54
|
|
|
$config['locale_cookie_secure'], |
|
55
|
|
|
$config['locale_cookie_http_only'], |
|
56
|
|
|
$container |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
$this->parseEngineBlockAttributeAggregationConfiguration( |
|
60
|
|
|
$config['attribute_aggregation_supported_attributes'], |
|
61
|
|
|
$container |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
// The user lifecycle can be disabled |
|
65
|
|
|
if (!$container->getParameter('user_lifecycle_enabled')) { |
|
66
|
|
|
$container->getDefinition(UserService::class) |
|
67
|
|
|
->removeMethodCall('setUserLifecycleApiClient'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
private function parseEngineBlockEntityIdConfiguration($engineBlockEntityId, ContainerBuilder $container) |
|
72
|
|
|
{ |
|
73
|
|
|
$container |
|
74
|
|
|
->getDefinition('OpenConext\Profile\Value\EntityId') |
|
75
|
|
|
->replaceArgument(0, $engineBlockEntityId); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
private function parseAttributeSupportMailConfiguration(array $attributeSupportConfig, ContainerBuilder $container) |
|
79
|
|
|
{ |
|
80
|
|
|
$container |
|
81
|
|
|
->getDefinition('profile.attribute_support.email_from') |
|
82
|
|
|
->replaceArgument(0, $attributeSupportConfig['email_from']); |
|
83
|
|
|
$container |
|
84
|
|
|
->getDefinition('profile.attribute_support.email_to') |
|
85
|
|
|
->replaceArgument(0, $attributeSupportConfig['email_to']); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
private function parseInformationRequestMailConfiguration(array $attributeSupportConfig, ContainerBuilder $container) |
|
89
|
|
|
{ |
|
90
|
|
|
$container |
|
91
|
|
|
->getDefinition('profile.information_request.email_from') |
|
92
|
|
|
->replaceArgument(0, $attributeSupportConfig['email_from']); |
|
93
|
|
|
$container |
|
94
|
|
|
->getDefinition('profile.information_request.email_to') |
|
95
|
|
|
->replaceArgument(0, $attributeSupportConfig['email_to']); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
private function parseDefaultLocaleConfiguration($defaultLocaleConfig, ContainerBuilder $container) |
|
99
|
|
|
{ |
|
100
|
|
|
$container |
|
101
|
|
|
->getDefinition(Locale::class) |
|
102
|
|
|
->replaceArgument(0, $defaultLocaleConfig); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
private function parseAvailableLocaleConfiguration(array $availableLocaleConfig, ContainerBuilder $container) |
|
106
|
|
|
{ |
|
107
|
|
|
$availableLocales = array_map(function ($availableLocale) { |
|
108
|
|
|
return new Definition(Locale::class, [$availableLocale]); |
|
109
|
|
|
}, $availableLocaleConfig); |
|
110
|
|
|
|
|
111
|
|
|
$container |
|
112
|
|
|
->getDefinition(LocaleSet::class) |
|
113
|
|
|
->replaceArgument(0, $availableLocales); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
private function parseLocaleCookieStorageConfiguration( |
|
117
|
|
|
$localeCookieDomain, |
|
118
|
|
|
$localeCookieKey, |
|
119
|
|
|
$localeCookieExpiresIn, |
|
120
|
|
|
$localeCookieSecure, |
|
121
|
|
|
$localeCookieHttpOnly, |
|
122
|
|
|
ContainerBuilder $container |
|
123
|
|
|
) { |
|
124
|
|
|
|
|
125
|
|
|
if ($localeCookieExpiresIn !== null) { |
|
126
|
|
|
$localeCookieExpirationDateDefinition = new Definition(DateTime::class); |
|
127
|
|
|
$localeCookieExpirationDateDefinition->addMethodCall('modify', [$localeCookieExpiresIn]); |
|
128
|
|
|
} else { |
|
129
|
|
|
$localeCookieExpirationDateDefinition = null; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$container |
|
133
|
|
|
->getDefinition(SingleCookieStorage::class) |
|
134
|
|
|
->replaceArgument(0, $localeCookieDomain) |
|
135
|
|
|
->replaceArgument(1, $localeCookieKey) |
|
136
|
|
|
->replaceArgument(2, $localeCookieExpirationDateDefinition) |
|
137
|
|
|
->replaceArgument(3, $localeCookieSecure) |
|
138
|
|
|
->replaceArgument(4, $localeCookieHttpOnly); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
private function parseEngineBlockAttributeAggregationConfiguration($aaConfig, ContainerBuilder $container) |
|
142
|
|
|
{ |
|
143
|
|
|
$container |
|
144
|
|
|
->getDefinition(AttributeAggregationEnabledAttributes::class) |
|
145
|
|
|
->replaceArgument(0, $aaConfig); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|