vendor/friendsofsymfony/user-bundle/src/DependencyInjection/Configuration.php line 231

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSUserBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\UserBundle\DependencyInjection;
  11. use FOS\UserBundle\Form\Type;
  12. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  13. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  14. use Symfony\Component\Config\Definition\ConfigurationInterface;
  15. /**
  16.  * This class contains the configuration information for the bundle.
  17.  *
  18.  * This information is solely responsible for how the different configuration
  19.  * sections are normalized, and merged.
  20.  *
  21.  * @author Christophe Coevoet <stof@notk.org>
  22.  *
  23.  * @internal
  24.  *
  25.  * @final
  26.  */
  27. class Configuration implements ConfigurationInterface
  28. {
  29.     public function getConfigTreeBuilder(): TreeBuilder
  30.     {
  31.         $treeBuilder = new TreeBuilder('fos_user');
  32.         $rootNode $treeBuilder->getRootNode();
  33.         $supportedDrivers = ['orm''mongodb''couchdb''custom'];
  34.         $rootNode
  35.             ->children()
  36.                 ->scalarNode('db_driver')
  37.                     ->validate()
  38.                         ->ifNotInArray($supportedDrivers)
  39.                         ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
  40.                     ->end()
  41.                     ->validate()
  42.                         ->ifInArray(['couchdb'])
  43.                         ->then(function ($v) {
  44.                             trigger_deprecation('friendsofsymfony/user-bundle''3.3.0''The CouchDB ODM integration is deprecated because the CouchDB ODM itself is unmaintained.');
  45.                             return $v;
  46.                         })
  47.                     ->end()
  48.                     ->cannotBeOverwritten()
  49.                     ->isRequired()
  50.                     ->cannotBeEmpty()
  51.                 ->end()
  52.                 ->scalarNode('user_class')->isRequired()->cannotBeEmpty()->end()
  53.                 ->scalarNode('firewall_name')->isRequired()->cannotBeEmpty()->end()
  54.                 ->scalarNode('model_manager_name')->defaultNull()->end()
  55.                 ->booleanNode('use_authentication_listener')->defaultTrue()->end()
  56.                 ->booleanNode('register_last_login')->defaultTrue()->end()
  57.                 ->booleanNode('use_listener')->defaultTrue()->end()
  58.                 ->booleanNode('use_flash_notifications')->defaultTrue()->end()
  59.                 ->booleanNode('use_username_form_type')->defaultTrue()->end()
  60.                 ->arrayNode('from_email')
  61.                     ->isRequired()
  62.                     ->children()
  63.                         ->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
  64.                         ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()
  65.                     ->end()
  66.                 ->end()
  67.             ->end()
  68.             // Using the custom driver requires changing the manager services
  69.             ->validate()
  70.                 ->ifTrue(function ($v) {
  71.                     return 'custom' === $v['db_driver'] && 'fos_user.user_manager.default' === $v['service']['user_manager'];
  72.                 })
  73.                 ->thenInvalid('You need to specify your own user manager service when using the "custom" driver.')
  74.             ->end();
  75.         $this->addProfileSection($rootNode);
  76.         $this->addChangePasswordSection($rootNode);
  77.         $this->addRegistrationSection($rootNode);
  78.         $this->addResettingSection($rootNode);
  79.         $this->addServiceSection($rootNode);
  80.         return $treeBuilder;
  81.     }
  82.     private function addProfileSection(ArrayNodeDefinition $node): void
  83.     {
  84.         $node
  85.             ->children()
  86.                 ->arrayNode('profile')
  87.                     ->addDefaultsIfNotSet()
  88.                     ->canBeUnset()
  89.                     ->children()
  90.                         ->arrayNode('form')
  91.                             ->addDefaultsIfNotSet()
  92.                             ->fixXmlConfig('validation_group')
  93.                             ->children()
  94.                                 ->scalarNode('type')->defaultValue(Type\ProfileFormType::class)->end()
  95.                                 ->scalarNode('name')->defaultValue('fos_user_profile_form')->end()
  96.                                 ->arrayNode('validation_groups')
  97.                                     ->prototype('scalar')->end()
  98.                                     ->defaultValue(['Profile''Default'])
  99.                                 ->end()
  100.                             ->end()
  101.                         ->end()
  102.                     ->end()
  103.                 ->end()
  104.             ->end();
  105.     }
  106.     private function addRegistrationSection(ArrayNodeDefinition $node): void
  107.     {
  108.         $node
  109.             ->children()
  110.                 ->arrayNode('registration')
  111.                     ->addDefaultsIfNotSet()
  112.                     ->canBeUnset()
  113.                     ->children()
  114.                         ->arrayNode('confirmation')
  115.                             ->addDefaultsIfNotSet()
  116.                             ->children()
  117.                                 ->booleanNode('enabled')->defaultFalse()->end()
  118.                                 ->scalarNode('template')->defaultValue('@FOSUser/Registration/email.txt.twig')->end()
  119.                                 ->arrayNode('from_email')
  120.                                     ->canBeUnset()
  121.                                     ->children()
  122.                                         ->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
  123.                                         ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()
  124.                                     ->end()
  125.                                 ->end()
  126.                             ->end()
  127.                         ->end()
  128.                         ->arrayNode('form')
  129.                             ->addDefaultsIfNotSet()
  130.                             ->children()
  131.                                 ->scalarNode('type')->defaultValue(Type\RegistrationFormType::class)->end()
  132.                                 ->scalarNode('name')->defaultValue('fos_user_registration_form')->end()
  133.                                 ->arrayNode('validation_groups')
  134.                                     ->prototype('scalar')->end()
  135.                                     ->defaultValue(['Registration''Default'])
  136.                                 ->end()
  137.                             ->end()
  138.                         ->end()
  139.                     ->end()
  140.                 ->end()
  141.             ->end();
  142.     }
  143.     private function addResettingSection(ArrayNodeDefinition $node): void
  144.     {
  145.         $node
  146.             ->children()
  147.                 ->arrayNode('resetting')
  148.                     ->addDefaultsIfNotSet()
  149.                     ->canBeUnset()
  150.                     ->children()
  151.                         ->scalarNode('retry_ttl')->defaultValue(7200)->end()
  152.                         ->scalarNode('token_ttl')->defaultValue(86400)->end()
  153.                         ->arrayNode('email')
  154.                             ->addDefaultsIfNotSet()
  155.                             ->children()
  156.                                 ->scalarNode('template')->defaultValue('@FOSUser/Resetting/email.txt.twig')->end()
  157.                                 ->arrayNode('from_email')
  158.                                     ->canBeUnset()
  159.                                     ->children()
  160.                                         ->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
  161.                                         ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()
  162.                                     ->end()
  163.                                 ->end()
  164.                             ->end()
  165.                         ->end()
  166.                         ->arrayNode('form')
  167.                             ->addDefaultsIfNotSet()
  168.                             ->children()
  169.                                 ->scalarNode('type')->defaultValue(Type\ResettingFormType::class)->end()
  170.                                 ->scalarNode('name')->defaultValue('fos_user_resetting_form')->end()
  171.                                 ->arrayNode('validation_groups')
  172.                                     ->prototype('scalar')->end()
  173.                                     ->defaultValue(['ResetPassword''Default'])
  174.                                 ->end()
  175.                             ->end()
  176.                         ->end()
  177.                     ->end()
  178.                 ->end()
  179.             ->end();
  180.     }
  181.     private function addChangePasswordSection(ArrayNodeDefinition $node): void
  182.     {
  183.         $node
  184.             ->children()
  185.                 ->arrayNode('change_password')
  186.                     ->addDefaultsIfNotSet()
  187.                     ->canBeUnset()
  188.                     ->children()
  189.                         ->arrayNode('form')
  190.                             ->addDefaultsIfNotSet()
  191.                             ->children()
  192.                                 ->scalarNode('type')->defaultValue(Type\ChangePasswordFormType::class)->end()
  193.                                 ->scalarNode('name')->defaultValue('fos_user_change_password_form')->end()
  194.                                 ->arrayNode('validation_groups')
  195.                                     ->prototype('scalar')->end()
  196.                                     ->defaultValue(['ChangePassword''Default'])
  197.                                 ->end()
  198.                             ->end()
  199.                         ->end()
  200.                     ->end()
  201.                 ->end()
  202.             ->end();
  203.     }
  204.     private function addServiceSection(ArrayNodeDefinition $node): void
  205.     {
  206.         $node
  207.             ->addDefaultsIfNotSet()
  208.             ->children()
  209.                 ->arrayNode('service')
  210.                     ->addDefaultsIfNotSet()
  211.                         ->children()
  212.                             ->scalarNode('mailer')
  213.                                 ->defaultNull()
  214.                                 ->validate()
  215.                                     ->ifInArray(['fos_user.mailer.twig_swift'])
  216.                                     ->then(function ($v) {
  217.                                         trigger_deprecation('friendsofsymfony/user-bundle''3.4.0''The twig_swift mailer is deprecated because Swiftmailer itself is unmaintained.');
  218.                                         return $v;
  219.                                     })
  220.                                 ->end()
  221.                             ->end()
  222.                             ->scalarNode('email_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()
  223.                             ->scalarNode('token_generator')->defaultValue('fos_user.util.token_generator.default')->end()
  224.                             ->scalarNode('username_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()
  225.                             ->scalarNode('user_manager')->defaultValue('fos_user.user_manager.default')->end()
  226.                         ->end()
  227.                     ->end()
  228.                 ->end()
  229.             ->end();
  230.     }
  231. }