vendor/jms/translation-bundle/JMS/TranslationBundle/DependencyInjection/Configuration.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  * http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. namespace JMS\TranslationBundle\DependencyInjection;
  18. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  19. use Symfony\Component\DependencyInjection\ContainerBuilder;
  20. use Symfony\Component\Config\Definition\ConfigurationInterface;
  21. class Configuration implements ConfigurationInterface
  22. {
  23.     private $container;
  24.     public function __construct(ContainerBuilder $container)
  25.     {
  26.         $this->container $container;
  27.     }
  28.     public function getConfigTreeBuilder()
  29.     {
  30.         $c $this->container;
  31.         $tb = new TreeBuilder();
  32.         $tb
  33.             ->root('jms_translation')
  34.                 ->fixXmlConfig('config')
  35.                 ->children()
  36.                     ->arrayNode('locales')
  37.                         ->prototype('scalar')->end()
  38.                     ->end()
  39.                     ->arrayNode('dumper')
  40.                         ->addDefaultsIfNotSet()
  41.                         ->children()
  42.                             ->booleanNode('add_date')->defaultTrue()->end()
  43.                             ->booleanNode('add_references')->defaultTrue()->end()
  44.                         ->end()
  45.                     ->end()
  46.                     ->scalarNode('source_language')->defaultValue('en')->end()
  47.                     ->arrayNode('configs')
  48.                         ->useAttributeAsKey('name')
  49.                         ->prototype('array')
  50.                             ->fixXmlConfig('dir''dirs')
  51.                             ->fixXmlConfig('excluded_dir')
  52.                             ->fixXmlConfig('excluded_name')
  53.                             ->fixXmlConfig('ignore_domain')
  54.                             ->fixXmlConfig('external_translations_dir')
  55.                             ->fixXmlConfig('domain')
  56.                             ->fixXmlConfig('extractor')
  57.                             ->children()
  58.                                 ->arrayNode('extractors')
  59.                                     ->prototype('scalar')->end()
  60.                                 ->end()
  61.                                 ->arrayNode('dirs')
  62.                                     ->requiresAtLeastOneElement()
  63.                                     ->prototype('scalar')
  64.                                         ->validate()
  65.                                             ->always(function ($v) use ($c) {
  66.                                                 $v str_replace(DIRECTORY_SEPARATOR'/'$v);
  67.                                                 if ('@' === $v[0]) {
  68.                                                     if (false === $pos strpos($v'/')) {
  69.                                                         $bundleName substr($v1);
  70.                                                     } else {
  71.                                                         $bundleName substr($v1$pos 1);
  72.                                                     }
  73.                                                     $bundles $c->getParameter('kernel.bundles');
  74.                                                     if (!isset($bundles[$bundleName])) {
  75.                                                         throw new \Exception(sprintf('The bundle "%s" does not exist. Available bundles: %s'$bundleNameimplode(', 'array_keys($bundles))));
  76.                                                     }
  77.                                                     $ref = new \ReflectionClass($bundles[$bundleName]);
  78.                                                     $v false === $pos dirname($ref->getFileName()) : dirname($ref->getFileName()).substr($v$pos);
  79.                                                 }
  80.                                                 if (!is_dir($v)) {
  81.                                                     throw new \Exception(sprintf('The directory "%s" does not exist.'$v));
  82.                                                 }
  83.                                                 return $v;
  84.                                             })
  85.                                         ->end()
  86.                                     ->end()
  87.                                 ->end()
  88.                                 ->arrayNode('excluded_dirs')
  89.                                     ->prototype('scalar')->end()
  90.                                 ->end()
  91.                                 ->arrayNode('excluded_names')
  92.                                     ->prototype('scalar')->end()
  93.                                 ->end()
  94.                                 ->arrayNode('external_translations_dirs')
  95.                                     ->prototype('scalar')->end()
  96.                                 ->end()
  97.                                 ->scalarNode('output_format')->end()
  98.                                 ->scalarNode('default_output_format')->end()
  99.                                 ->arrayNode('ignored_domains')
  100.                                     ->prototype('scalar')->end()
  101.                                 ->end()
  102.                                 ->arrayNode('domains')
  103.                                     ->prototype('scalar')->end()
  104.                                 ->end()
  105.                                 ->scalarNode('output_dir')->isRequired()->cannotBeEmpty()->end()
  106.                                 ->scalarNode('keep')->defaultValue(false)->end()
  107.                             ->end()
  108.                         ->end()
  109.                     ->end()
  110.                 ->end()
  111.             ->end()
  112.         ;
  113.         return $tb;
  114.     }
  115. }