1 | <?php |
||
22 | class Configuration implements ConfigurationInterface |
||
23 | { |
||
24 | private $container; |
||
25 | |||
26 | 17 | public function __construct(ContainerBuilder $container) |
|
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | 17 | public function getConfigTreeBuilder() |
|
84 | |||
85 | /** |
||
86 | * @param ArrayNodeDefinition $root |
||
87 | */ |
||
88 | 17 | private function configsNode(ArrayNodeDefinition $root) |
|
89 | { |
||
90 | 17 | $container = $this->container; |
|
91 | 17 | $root->children() |
|
92 | 17 | ->arrayNode('configs') |
|
93 | 17 | ->addDefaultChildrenIfNoneSet('default') |
|
94 | 17 | ->useAttributeAsKey('name') |
|
95 | 17 | ->prototype('array') |
|
96 | 17 | ->fixXmlConfig('dir', 'dirs') |
|
97 | 17 | ->fixXmlConfig('excluded_dir') |
|
98 | 17 | ->fixXmlConfig('excluded_name') |
|
99 | 17 | ->fixXmlConfig('blacklist_domain') |
|
100 | 17 | ->fixXmlConfig('external_translations_dir') |
|
101 | 17 | ->fixXmlConfig('whitelist_domain') |
|
102 | 17 | ->children() |
|
103 | 17 | ->arrayNode('dirs') |
|
104 | 17 | ->info('Directories we should scan for translations') |
|
105 | 17 | ->prototype('scalar') |
|
106 | 17 | ->validate() |
|
107 | ->always(function ($value) use ($container) { |
||
108 | 5 | $value = str_replace(DIRECTORY_SEPARATOR, '/', $value); |
|
109 | |||
110 | 5 | if ('@' === $value[0]) { |
|
111 | if (false === $pos = strpos($value, '/')) { |
||
112 | $bundleName = substr($value, 1); |
||
113 | } else { |
||
114 | $bundleName = substr($value, 1, $pos - 2); |
||
115 | } |
||
116 | |||
117 | $bundles = $container->getParameter('kernel.bundles'); |
||
118 | if (!isset($bundles[$bundleName])) { |
||
119 | throw new \Exception(sprintf('The bundle "%s" does not exist. Available bundles: %s', $bundleName, array_keys($bundles))); |
||
120 | } |
||
121 | |||
122 | $ref = new \ReflectionClass($bundles[$bundleName]); |
||
123 | $value = false === $pos ? dirname($ref->getFileName()) : dirname($ref->getFileName()).substr($value, $pos); |
||
124 | } |
||
125 | |||
126 | 5 | if (!is_dir($value)) { |
|
127 | throw new \Exception(sprintf('The directory "%s" does not exist.', $value)); |
||
128 | } |
||
129 | |||
130 | 5 | return $value; |
|
131 | 17 | }) |
|
132 | 17 | ->end() |
|
133 | 17 | ->end() |
|
134 | 17 | ->end() |
|
135 | 17 | ->arrayNode('excluded_dirs') |
|
136 | 17 | ->prototype('scalar')->end() |
|
137 | 17 | ->end() |
|
138 | 17 | ->arrayNode('excluded_names') |
|
139 | 17 | ->prototype('scalar')->end() |
|
140 | 17 | ->end() |
|
141 | 17 | ->arrayNode('external_translations_dirs') |
|
142 | 17 | ->prototype('scalar')->end() |
|
143 | 17 | ->end() |
|
144 | 17 | ->enumNode('output_format')->values(['php', 'yml', 'xlf'])->defaultValue('xlf')->end() |
|
145 | 17 | ->arrayNode('blacklist_domains') |
|
146 | 17 | ->prototype('scalar')->end() |
|
147 | 17 | ->end() |
|
148 | 17 | ->arrayNode('whitelist_domains') |
|
149 | 17 | ->prototype('scalar')->end() |
|
150 | 17 | ->end() |
|
151 | 17 | ->arrayNode('remote_storage') |
|
152 | 17 | ->info('Service ids with to classes that supports remote storage of translations.') |
|
153 | 17 | ->prototype('scalar')->end() |
|
154 | 17 | ->end() |
|
155 | 17 | ->arrayNode('local_storage') |
|
156 | 17 | ->defaultValue(['php_translation.local_file_storage.abstract']) |
|
157 | 17 | ->info('Service ids with to classes that supports local storage of translations.') |
|
158 | 17 | ->prototype('scalar')->end() |
|
159 | 17 | ->end() |
|
160 | 17 | ->scalarNode('output_dir')->cannotBeEmpty()->defaultValue('%kernel.root_dir%/Resources/translations')->end() |
|
161 | 17 | ->scalarNode('project_root')->info("The root dir of your project. By default this will be kernel_root's parent. ")->end() |
|
162 | 17 | ->variableNode('local_file_storage_options') |
|
163 | 17 | ->info('Options passed to the local file storage\'s dumper.') |
|
164 | 17 | ->defaultValue([]) |
|
165 | 17 | ->validate() |
|
166 | 17 | ->ifTrue(function ($value) { |
|
167 | return !is_array($value); |
||
168 | 17 | }) |
|
169 | 17 | ->thenInvalid('"local_file_storage_options" must be an array.') |
|
170 | 17 | ->end() |
|
171 | 17 | ->end() |
|
172 | 17 | ->end() |
|
173 | 17 | ->end() |
|
174 | 17 | ->end() |
|
175 | 17 | ->end(); |
|
176 | 17 | } |
|
177 | |||
178 | 17 | private function addAutoTranslateNode(ArrayNodeDefinition $root) |
|
190 | |||
191 | 17 | private function addEditInPlaceNode(ArrayNodeDefinition $root) |
|
204 | |||
205 | 17 | private function addWebUINode(ArrayNodeDefinition $root) |
|
217 | } |
||
218 |