vendor/presta/sitemap-bundle/DependencyInjection/Configuration.php line 31

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the PrestaSitemapBundle package.
  4.  *
  5.  * (c) PrestaConcept <www.prestaconcept.net>
  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 Presta\SitemapBundle\DependencyInjection;
  11. use Presta\SitemapBundle\Sitemap\Url\UrlConcrete;
  12. use Presta\SitemapBundle\Sitemap\XmlConstraint;
  13. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  14. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  15. use Symfony\Component\Config\Definition\ConfigurationInterface;
  16. use Symfony\Component\HttpKernel\Kernel;
  17. /**
  18.  * This is the class that validates and merges configuration from your app/config files
  19.  */
  20. class Configuration implements ConfigurationInterface
  21. {
  22.     const DEFAULT_FILENAME 'sitemap';
  23.     /**
  24.      * @inheritDoc
  25.      */
  26.     public function getConfigTreeBuilder()
  27.     {
  28.         if (method_exists(TreeBuilder::class, 'getRootNode')) {
  29.             $treeBuilder = new TreeBuilder('presta_sitemap');
  30.             $rootNode $treeBuilder->getRootNode();
  31.         } else {
  32.             $treeBuilder = new TreeBuilder();
  33.             $rootNode $treeBuilder->root('presta_sitemap');
  34.         }
  35.         $rootNode
  36.             ->children()
  37.                 ->scalarNode('generator')->defaultValue('presta_sitemap.generator_default')->end()
  38.                 ->scalarNode('dumper')->defaultValue('presta_sitemap.dumper_default')->end()
  39.                 ->integerNode('timetolive')
  40.                     ->defaultValue(3600)
  41.                 ->end()
  42.                 ->scalarNode('sitemap_file_prefix')
  43.                     ->defaultValue(self::DEFAULT_FILENAME)
  44.                     ->info('Sets sitemap filename prefix defaults to "sitemap" -> sitemap.xml (for index); sitemap.<section>.xml(.gz) (for sitemaps)')
  45.                 ->end()
  46.                 ->integerNode('items_by_set')
  47.                     // Add one to the limit items value because it's an
  48.                     // index value (not a quantity)
  49.                     ->defaultValue(XmlConstraint::LIMIT_ITEMS 1)
  50.                     ->info('The maximum number of items allowed in single sitemap.')
  51.                 ->end()
  52.                 ->scalarNode('route_annotation_listener')->defaultTrue()->end()
  53.                 ->scalarNode('dump_directory')
  54.                     ->info(
  55.                         'The directory to which the sitemap will be dumped. '.
  56.                         'It can be either absolute, or relative (to the place where the command will be triggered). '.
  57.                         'Default to Symfony\'s public dir.'
  58.                     )
  59.                     ->defaultValue(
  60.                         '%kernel.project_dir%/'.(version_compare(Kernel::VERSION'4.0') >= 'public' 'web')
  61.                     )
  62.                 ->end()
  63.                 ->arrayNode('defaults')
  64.                     ->addDefaultsIfNotSet()
  65.                     ->children()
  66.                         ->scalarNode('priority')->defaultValue(0.5)->end()
  67.                         ->scalarNode('changefreq')->defaultValue(UrlConcrete::CHANGEFREQ_DAILY)->end()
  68.                         ->scalarNode('lastmod')->defaultValue('now')->end()
  69.                     ->end()
  70.                 ->end()
  71.                 ->scalarNode('default_section')
  72.                     ->defaultValue('default')
  73.                     ->info('The default section in which static routes are registered.')
  74.                 ->end()
  75.             ->end()
  76.         ;
  77.         $this->addAlternateSection($rootNode);
  78.         return $treeBuilder;
  79.     }
  80.     private function addAlternateSection(ArrayNodeDefinition $rootNode)
  81.     {
  82.         $rootNode
  83.             ->children()
  84.                 ->arrayNode('alternate')
  85.                     ->info(
  86.                         'Automatically generate alternate (hreflang) urls with static routes.' .
  87.                        ' Requires route_annotation_listener config to be enabled.'
  88.                     )
  89.                     ->canBeEnabled()
  90.                     ->children()
  91.                         ->scalarNode('default_locale')
  92.                             ->defaultValue('en')
  93.                             ->info('The default locale of your routes.')
  94.                         ->end()
  95.                         ->arrayNode('locales')
  96.                             ->defaultValue(['en'])
  97.                             ->beforeNormalization()
  98.                             ->ifString()
  99.                                 ->then(function ($v) { return preg_split('/\s*,\s*/'$v); })
  100.                             ->end()
  101.                             ->prototype('scalar')->end()
  102.                             ->info('List of supported locales of your routes.')
  103.                         ->end()
  104.                         ->enumNode('i18n')
  105.                             ->defaultValue('symfony')
  106.                             ->values(['symfony''jms'])
  107.                             ->info('Strategy used to create your i18n routes.')
  108.                         ->end()
  109.                     ->end()
  110.                 ->end()
  111.             ->end()
  112.         ;
  113.     }
  114. }