|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Http\HttplugBundle\DependencyInjection; |
| 4 | + |
| 5 | +use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
| 6 | +use Symfony\Component\Config\Definition\ConfigurationInterface; |
| 7 | +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
| 8 | + |
| 9 | +/** |
| 10 | + * This class contains the configuration information for the bundle |
| 11 | + * |
| 12 | + * This information is solely responsible for how the different configuration |
| 13 | + * sections are normalized, and merged. |
| 14 | + * |
| 15 | + * @author David Buchmann <mail@davidbu.ch> |
| 16 | + */ |
| 17 | +class Configuration implements ConfigurationInterface |
| 18 | +{ |
| 19 | + /** |
| 20 | + * {@inheritdoc} |
| 21 | + */ |
| 22 | + public function getConfigTreeBuilder() |
| 23 | + { |
| 24 | + $treeBuilder = new TreeBuilder(); |
| 25 | + $rootNode = $treeBuilder->root('httplug'); |
| 26 | + |
| 27 | + $rootNode |
| 28 | + ->validate() |
| 29 | + ->ifTrue(function ($v) { |
| 30 | + return !empty($v['classes']['client']) |
| 31 | + || !empty($v['classes']['message_factory']) |
| 32 | + || !empty($v['classes']['uri_factory']) |
| 33 | + ; |
| 34 | + }) |
| 35 | + ->then(function ($v) { |
| 36 | + foreach ($v['classes'] as $key => $class) { |
| 37 | + if (null !== $class && !class_exists($class)) { |
| 38 | + throw new InvalidConfigurationException(sprintf( |
| 39 | + 'Class %s specified for httplug.classes.%s does not exist.', |
| 40 | + $class, |
| 41 | + $key |
| 42 | + )); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + return $v; |
| 47 | + }) |
| 48 | + ->end() |
| 49 | + ->children() |
| 50 | + ->arrayNode('main_alias') |
| 51 | + ->addDefaultsIfNotSet() |
| 52 | + ->info('Configure which service the main alias point to.') |
| 53 | + ->children() |
| 54 | + ->scalarNode('client')->defaultValue('httplug.client.default')->end() |
| 55 | + ->scalarNode('message_factory')->defaultValue('httplug.message_factory.default')->end() |
| 56 | + ->scalarNode('uri_factory')->defaultValue('httplug.uri_factory.default')->end() |
| 57 | + ->end() |
| 58 | + ->end() |
| 59 | + ->arrayNode('classes') |
| 60 | + ->addDefaultsIfNotSet() |
| 61 | + ->info('Overwrite a service class instead of using the discovery mechanism.') |
| 62 | + ->children() |
| 63 | + ->scalarNode('client')->defaultNull()->end() |
| 64 | + ->scalarNode('message_factory')->defaultNull()->end() |
| 65 | + ->scalarNode('uri_factory')->defaultNull()->end() |
| 66 | + ->end() |
| 67 | + ->end() |
| 68 | + ->end() |
| 69 | + ; |
| 70 | + |
| 71 | + return $treeBuilder; |
| 72 | + } |
| 73 | +} |
0 commit comments