vendor/php-translation/symfony-bundle/DependencyInjection/Configuration.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the PHP Translation package.
  4.  *
  5.  * (c) PHP Translation team <tobias.nyholm@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Translation\Bundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  12. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  13. use Symfony\Component\Config\Definition\ConfigurationInterface;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. /**
  16.  * This is the class that validates and merges configuration from your app/config files.
  17.  */
  18. class Configuration implements ConfigurationInterface
  19. {
  20.     private $container;
  21.     public function __construct(ContainerBuilder $container)
  22.     {
  23.         $this->container $container;
  24.     }
  25.     /**
  26.      * {@inheritdoc}
  27.      */
  28.     public function getConfigTreeBuilder()
  29.     {
  30.         $treeBuilder = new TreeBuilder();
  31.         $root $treeBuilder->root('translation');
  32.         $this->configsNode($root);
  33.         $this->addAutoTranslateNode($root);
  34.         $this->addEditInPlaceNode($root);
  35.         $this->addWebUINode($root);
  36.         $debug $this->container->getParameter('kernel.debug');
  37.         $root
  38.             ->children()
  39.                 ->arrayNode('locales')
  40.                     ->prototype('scalar')->end()
  41.                 ->end()
  42.                 ->scalarNode('default_locale')->info('Your default language or fallback locale. Default will be kernel.default_locale')->end()
  43.                 ->arrayNode('symfony_profiler')
  44.                     ->addDefaultsIfNotSet()
  45.                     ->treatFalseLike(['enabled' => false])
  46.                     ->treatTrueLike(['enabled' => true])
  47.                     ->treatNullLike(['enabled' => $debug])
  48.                     ->info('Extend the debug profiler with information about requests.')
  49.                     ->children()
  50.                         ->booleanNode('enabled')
  51.                             ->info('Turn the symfony profiler integration on or off. Defaults to kernel debug mode.')
  52.                             ->defaultValue($debug)
  53.                         ->end()
  54.                         ->scalarNode('formatter')->defaultNull()->end()
  55.                         ->integerNode('captured_body_length')
  56.                             ->defaultValue(0)
  57.                             ->info('Limit long HTTP message bodies to x characters. If set to 0 we do not read the message body. Only available with the default formatter (FullHttpMessageFormatter).')
  58.                         ->end()
  59.                     ->end()
  60.                     ->children()
  61.                         ->booleanNode('allow_edit')->defaultTrue()->end()
  62.                     ->end()
  63.                 ->end()
  64.                 ->arrayNode('auto_add_missing_translations')
  65.                     ->canBeEnabled()
  66.                     ->children()
  67.                         ->scalarNode('config_name')->defaultValue('default')->end()
  68.                     ->end()
  69.                 ->end()
  70.                 ->scalarNode('http_client')->cannotBeEmpty()->defaultValue('httplug.client')->end()
  71.                 ->scalarNode('message_factory')->cannotBeEmpty()->defaultValue('httplug.message_factory')->end()
  72.             ->end();
  73.         return $treeBuilder;
  74.     }
  75.     /**
  76.      * @param ArrayNodeDefinition $root
  77.      */
  78.     private function configsNode(ArrayNodeDefinition $root)
  79.     {
  80.         $container $this->container;
  81.         $root->children()
  82.             ->arrayNode('configs')
  83.             ->addDefaultChildrenIfNoneSet('default')
  84.                 ->useAttributeAsKey('name')
  85.                 ->prototype('array')
  86.                     ->fixXmlConfig('dir''dirs')
  87.                     ->fixXmlConfig('excluded_dir')
  88.                     ->fixXmlConfig('excluded_name')
  89.                     ->fixXmlConfig('blacklist_domain')
  90.                     ->fixXmlConfig('external_translations_dir')
  91.                     ->fixXmlConfig('whitelist_domain')
  92.                     ->children()
  93.                         ->arrayNode('dirs')
  94.                             ->info('Directories we should scan for translations')
  95.                             ->prototype('scalar')
  96.                                 ->validate()
  97.                                     ->always(function ($value) use ($container) {
  98.                                         $value str_replace(DIRECTORY_SEPARATOR'/'$value);
  99.                                         if ('@' === $value[0]) {
  100.                                             if (false === $pos strpos($value'/')) {
  101.                                                 $bundleName substr($value1);
  102.                                             } else {
  103.                                                 $bundleName substr($value1$pos 2);
  104.                                             }
  105.                                             $bundles $container->getParameter('kernel.bundles');
  106.                                             if (!isset($bundles[$bundleName])) {
  107.                                                 throw new \Exception(sprintf('The bundle "%s" does not exist. Available bundles: %s'$bundleNamearray_keys($bundles)));
  108.                                             }
  109.                                             $ref = new \ReflectionClass($bundles[$bundleName]);
  110.                                             $value false === $pos dirname($ref->getFileName()) : dirname($ref->getFileName()).substr($value$pos);
  111.                                         }
  112.                                         if (!is_dir($value)) {
  113.                                             throw new \Exception(sprintf('The directory "%s" does not exist.'$value));
  114.                                         }
  115.                                         return $value;
  116.                                     })
  117.                                 ->end()
  118.                             ->end()
  119.                         ->end()
  120.                         ->arrayNode('excluded_dirs')
  121.                             ->prototype('scalar')->end()
  122.                         ->end()
  123.                         ->arrayNode('excluded_names')
  124.                             ->prototype('scalar')->end()
  125.                         ->end()
  126.                         ->arrayNode('external_translations_dirs')
  127.                             ->prototype('scalar')->end()
  128.                         ->end()
  129.                         ->enumNode('output_format')->values(['php''yml''xlf''po'])->defaultValue('xlf')->end()
  130.                         ->arrayNode('blacklist_domains')
  131.                             ->prototype('scalar')->end()
  132.                         ->end()
  133.                         ->arrayNode('whitelist_domains')
  134.                             ->prototype('scalar')->end()
  135.                         ->end()
  136.                         ->arrayNode('remote_storage')
  137.                             ->info('Service ids with to classes that supports remote storage of translations.')
  138.                             ->prototype('scalar')->end()
  139.                         ->end()
  140.                         ->arrayNode('local_storage')
  141.                             ->defaultValue(['php_translation.local_file_storage.abstract'])
  142.                             ->info('Service ids with to classes that supports local storage of translations.')
  143.                             ->prototype('scalar')->end()
  144.                         ->end()
  145.                         ->scalarNode('output_dir')->cannotBeEmpty()->defaultValue('%kernel.root_dir%/Resources/translations')->end()
  146.                         ->scalarNode('project_root')->info("The root dir of your project. By default this will be kernel_root's parent.")->end()
  147.                         ->scalarNode('xliff_version')->info('The version of XLIFF XML you want to use (if dumping to this format).')->defaultValue('2.0')->end()
  148.                         ->variableNode('local_file_storage_options')
  149.                             ->info('Options passed to the local file storage\'s dumper.')
  150.                             ->defaultValue([])
  151.                             ->validate()
  152.                                 ->ifTrue(function ($value) {
  153.                                     return !is_array($value);
  154.                                 })
  155.                                 ->thenInvalid('"local_file_storage_options" must be an array.')
  156.                             ->end()
  157.                         ->end()
  158.                     ->end()
  159.                 ->end()
  160.             ->end()
  161.         ->end();
  162.     }
  163.     private function addAutoTranslateNode(ArrayNodeDefinition $root)
  164.     {
  165.         $root->children()
  166.             ->arrayNode('fallback_translation')
  167.                 ->canBeEnabled()
  168.                 ->children()
  169.                     ->enumNode('service')->values(['google''yandex'])->defaultValue('google')->end()
  170.                     ->scalarNode('api_key')->defaultNull()->end()
  171.                 ->end()
  172.             ->end()
  173.         ->end();
  174.     }
  175.     private function addEditInPlaceNode(ArrayNodeDefinition $root)
  176.     {
  177.         $root->children()
  178.             ->arrayNode('edit_in_place')
  179.                 ->canBeEnabled()
  180.                 ->children()
  181.                     ->scalarNode('config_name')->defaultValue('default')->end()
  182.                     ->scalarNode('activator')->cannotBeEmpty()->defaultValue('php_translation.edit_in_place.activator')->end()
  183.                     ->scalarNode('show_untranslatable')->defaultTrue()->end()
  184.                 ->end()
  185.             ->end()
  186.         ->end();
  187.     }
  188.     private function addWebUINode(ArrayNodeDefinition $root)
  189.     {
  190.         $root->children()
  191.             ->arrayNode('webui')
  192.                 ->canBeEnabled()
  193.                 ->children()
  194.                     ->booleanNode('allow_create')->defaultTrue()->end()
  195.                     ->booleanNode('allow_delete')->defaultTrue()->end()
  196.                     ->scalarNode('file_base_path')->defaultNull()->info('Base path for SourceLocation\'s. Defaults to "%kernel.project_dir%".')->end()
  197.                 ->end()
  198.             ->end()
  199.         ->end();
  200.     }
  201. }