vendor/sendinblue/api-bundle/DependencyInjection/Configuration.php line 63

Open in your IDE?
  1. <?php
  2. namespace SendinBlue\Bundle\ApiBundle\DependencyInjection;
  3. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  4. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  5. use Symfony\Component\Config\Definition\ConfigurationInterface;
  6. class Configuration implements ConfigurationInterface
  7. {
  8.     /**
  9.      * {@inheritdoc}
  10.      */
  11.     public function getConfigTreeBuilder()
  12.     {
  13.         $treeBuilder = new TreeBuilder();
  14.         $rootNode $treeBuilder->root('sendinblue_api');
  15.         $rootNode
  16.             ->beforeNormalization()
  17.                 ->ifTrue(function ($configuration) {
  18.                     return \is_array($configuration)
  19.                         && !\array_key_exists('clients'$configuration)
  20.                         && !\array_key_exists('client'$configuration)
  21.                     ;
  22.                 })
  23.                 ->then(function ($configuration) {
  24.                     $defaultClient 'default';
  25.                     if (isset($configuration['default_client'])) {
  26.                         $defaultClient $configuration['default_client'];
  27.                         unset($configuration['default_client']);
  28.                     }
  29.                     $clientConfiguration = [];
  30.                     foreach (['key''endpoints'] as $clientKey) {
  31.                         if (\array_key_exists($clientKey$configuration)) {
  32.                             $clientConfiguration[$clientKey] = $configuration[$clientKey];
  33.                             unset($configuration[$clientKey]);
  34.                         }
  35.                     }
  36.                     $configuration['clients'] = [$defaultClient => $clientConfiguration];
  37.                     return $configuration;
  38.                 })
  39.             ->end()
  40.             ->children()
  41.                 ->scalarNode('default_client')->end()
  42.             ->end()
  43.             ->fixXmlConfig('client')
  44.             ->append($this->getClientsNode())
  45.         ;
  46.         return $treeBuilder;
  47.     }
  48.     /**
  49.      * @return ArrayNodeDefinition
  50.      */
  51.     private function getClientsNode()
  52.     {
  53.         $treeBuilder = new TreeBuilder();
  54.         $node $treeBuilder->root('clients');
  55.         $node
  56.             ->requiresAtLeastOneElement()
  57.             ->useAttributeAsKey('name')
  58.             ->prototype('array')
  59.                 ->fixXmlConfig('endpoint')
  60.                 ->children()
  61.                     ->arrayNode('endpoints')
  62.                         ->prototype('enum')
  63.                             ->values(SendinBlueApiExtension::getEndpoints())
  64.                         ->end()
  65.                     ->end()
  66.                     ->scalarNode('key')->isRequired()->cannotBeEmpty()->end()
  67.                 ->end()
  68.             ->end()
  69.         ;
  70.         return $node;
  71.     }
  72. }