|
8 | 8 | use phpDocumentor\Guides\RestructuredText\Nodes\ConfvalNode; |
9 | 9 | use phpDocumentor\Guides\RestructuredText\Nodes\OptionNode; |
10 | 10 | use phpDocumentor\Guides\RestructuredText\Nodes\VersionChangeNode; |
| 11 | +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
| 12 | +use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
| 13 | +use Symfony\Component\Config\Definition\ConfigurationInterface; |
11 | 14 | use Symfony\Component\Config\FileLocator; |
12 | 15 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
13 | 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
14 | 17 | use Symfony\Component\DependencyInjection\Extension\Extension; |
15 | 18 | use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
16 | 19 | use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
17 | 20 |
|
| 21 | +use function assert; |
18 | 22 | use function dirname; |
19 | 23 | use function phpDocumentor\Guides\DependencyInjection\template; |
20 | 24 |
|
21 | | -class ReStructuredTextExtension extends Extension implements PrependExtensionInterface, CompilerPassInterface |
| 25 | +final class ReStructuredTextExtension extends Extension implements |
| 26 | + PrependExtensionInterface, |
| 27 | + CompilerPassInterface, |
| 28 | + ConfigurationInterface |
22 | 29 | { |
23 | 30 | /** @param mixed[] $configs */ |
24 | 31 | public function load(array $configs, ContainerBuilder $container): void |
25 | 32 | { |
| 33 | + $configuration = $this->getConfiguration($configs, $container); |
| 34 | + $config = $this->processConfiguration($configuration, $configs); |
26 | 35 | $loader = new PhpFileLoader( |
27 | 36 | $container, |
28 | 37 | new FileLocator(dirname(__DIR__, 3) . '/resources/config'), |
29 | 38 | ); |
30 | 39 |
|
| 40 | + $normalizedLanguageLabels = []; |
| 41 | + foreach ($config['code_language_labels'] ?? [] as $item) { |
| 42 | + $normalizedLanguageLabels[$item['language']] = $item['label']; |
| 43 | + } |
| 44 | + |
| 45 | + $container->setParameter('phpdoc.rst.code_language_labels', $normalizedLanguageLabels); |
31 | 46 | $loader->load('guides-restructured-text.php'); |
32 | 47 | } |
33 | 48 |
|
@@ -55,4 +70,36 @@ public function process(ContainerBuilder $container): void |
55 | 70 | { |
56 | 71 | (new TextRolePass())->process($container); |
57 | 72 | } |
| 73 | + |
| 74 | + public function getConfigTreeBuilder(): TreeBuilder |
| 75 | + { |
| 76 | + $treeBuilder = new TreeBuilder('rst'); |
| 77 | + $rootNode = $treeBuilder->getRootNode(); |
| 78 | + assert($rootNode instanceof ArrayNodeDefinition); |
| 79 | + |
| 80 | + $rootNode |
| 81 | + ->fixXmlConfig('code_language_label', 'code_language_labels') |
| 82 | + ->children() |
| 83 | + ->arrayNode('code_language_labels') |
| 84 | + ->arrayPrototype() |
| 85 | + ->children() |
| 86 | + ->scalarNode('language') |
| 87 | + ->isRequired() |
| 88 | + ->end() |
| 89 | + ->scalarNode('label') |
| 90 | + ->isRequired() |
| 91 | + ->end() |
| 92 | + ->end() |
| 93 | + ->end() |
| 94 | + ->end() |
| 95 | + ->end(); |
| 96 | + |
| 97 | + return $treeBuilder; |
| 98 | + } |
| 99 | + |
| 100 | + /** @param mixed[] $config */ |
| 101 | + public function getConfiguration(array $config, ContainerBuilder $container): static |
| 102 | + { |
| 103 | + return $this; |
| 104 | + } |
58 | 105 | } |
0 commit comments