vendor/friendsofsymfony/user-bundle/DependencyInjection/Configuration.php line 35

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 <[email protected]>
  22.  */
  23. class Configuration implements ConfigurationInterface
  24. {
  25.     /**
  26.      * {@inheritdoc}
  27.      */
  28.     public function getConfigTreeBuilder()
  29.     {
  30.         $treeBuilder = new TreeBuilder();
  31.         $rootNode $treeBuilder->root('fos_user');
  32.         $supportedDrivers = array('orm''mongodb''couchdb''custom');
  33.         $rootNode
  34.             ->children()
  35.                 ->scalarNode('db_driver')
  36.                     ->validate()
  37.                         ->ifNotInArray($supportedDrivers)
  38.                         ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
  39.                     ->end()
  40.                     ->cannotBeOverwritten()
  41.                     ->isRequired()
  42.                     ->cannotBeEmpty()
  43.                 ->end()
  44.                 ->scalarNode('user_class')->isRequired()->cannotBeEmpty()->end()
  45.                 ->scalarNode('firewall_name')->isRequired()->cannotBeEmpty()->end()
  46.                 ->scalarNode('model_manager_name')->defaultNull()->end()
  47.                 ->booleanNode('use_authentication_listener')->defaultTrue()->end()
  48.                 ->booleanNode('use_listener')->defaultTrue()->end()
  49.                 ->booleanNode('use_flash_notifications')->defaultTrue()->end()
  50.                 ->booleanNode('use_username_form_type')->defaultTrue()->end()
  51.                 ->arrayNode('from_email')
  52.                     ->isRequired()
  53.                     ->children()
  54.                         ->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
  55.                         ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()
  56.                     ->end()
  57.                 ->end()
  58.             ->end()
  59.             // Using the custom driver requires changing the manager services
  60.             ->validate()
  61.                 ->ifTrue(function ($v) {
  62.                     return 'custom' === $v['db_driver'] && 'fos_user.user_manager.default' === $v['service']['user_manager'];
  63.                 })
  64.                 ->thenInvalid('You need to specify your own user manager service when using the "custom" driver.')
  65.             ->end()
  66.             ->validate()
  67.                 ->ifTrue(function ($v) {
  68.                     return 'custom' === $v['db_driver'] && !empty($v['group']) && 'fos_user.group_manager.default' === $v['group']['group_manager'];
  69.                 })
  70.                 ->thenInvalid('You need to specify your own group manager service when using the "custom" driver.')
  71.             ->end();
  72.         $this->addProfileSection($rootNode);
  73.         $this->addChangePasswordSection($rootNode);
  74.         $this->addRegistrationSection($rootNode);
  75.         $this->addResettingSection($rootNode);
  76.         $this->addServiceSection($rootNode);
  77.         $this->addGroupSection($rootNode);
  78.         return $treeBuilder;
  79.     }
  80.     /**
  81.      * @param ArrayNodeDefinition $node
  82.      */
  83.     private function addProfileSection(ArrayNodeDefinition $node)
  84.     {
  85.         $node
  86.             ->children()
  87.                 ->arrayNode('profile')
  88.                     ->addDefaultsIfNotSet()
  89.                     ->canBeUnset()
  90.                     ->children()
  91.                         ->arrayNode('form')
  92.                             ->addDefaultsIfNotSet()
  93.                             ->fixXmlConfig('validation_group')
  94.                             ->children()
  95.                                 ->scalarNode('type')->defaultValue(Type\ProfileFormType::class)->end()
  96.                                 ->scalarNode('name')->defaultValue('fos_user_profile_form')->end()
  97.                                 ->arrayNode('validation_groups')
  98.                                     ->prototype('scalar')->end()
  99.                                     ->defaultValue(array('Profile''Default'))
  100.                                 ->end()
  101.                             ->end()
  102.                         ->end()
  103.                     ->end()
  104.                 ->end()
  105.             ->end();
  106.     }
  107.     /**
  108.      * @param ArrayNodeDefinition $node
  109.      */
  110.     private function addRegistrationSection(ArrayNodeDefinition $node)
  111.     {
  112.         $node
  113.             ->children()
  114.                 ->arrayNode('registration')
  115.                     ->addDefaultsIfNotSet()
  116.                     ->canBeUnset()
  117.                     ->children()
  118.                         ->arrayNode('confirmation')
  119.                             ->addDefaultsIfNotSet()
  120.                             ->children()
  121.                                 ->booleanNode('enabled')->defaultFalse()->end()
  122.                                 ->scalarNode('template')->defaultValue('@FOSUser/Registration/email.txt.twig')->end()
  123.                                 ->arrayNode('from_email')
  124.                                     ->canBeUnset()
  125.                                     ->children()
  126.                                         ->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
  127.                                         ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()
  128.                                     ->end()
  129.                                 ->end()
  130.                             ->end()
  131.                         ->end()
  132.                         ->arrayNode('form')
  133.                             ->addDefaultsIfNotSet()
  134.                             ->children()
  135.                                 ->scalarNode('type')->defaultValue(Type\RegistrationFormType::class)->end()
  136.                                 ->scalarNode('name')->defaultValue('fos_user_registration_form')->end()
  137.                                 ->arrayNode('validation_groups')
  138.                                     ->prototype('scalar')->end()
  139.                                     ->defaultValue(array('Registration''Default'))
  140.                                 ->end()
  141.                             ->end()
  142.                         ->end()
  143.                     ->end()
  144.                 ->end()
  145.             ->end();
  146.     }
  147.     /**
  148.      * @param ArrayNodeDefinition $node
  149.      */
  150.     private function addResettingSection(ArrayNodeDefinition $node)
  151.     {
  152.         $node
  153.             ->children()
  154.                 ->arrayNode('resetting')
  155.                     ->addDefaultsIfNotSet()
  156.                     ->canBeUnset()
  157.                     ->children()
  158.                         ->scalarNode('retry_ttl')->defaultValue(7200)->end()
  159.                         ->scalarNode('token_ttl')->defaultValue(86400)->end()
  160.                         ->arrayNode('email')
  161.                             ->addDefaultsIfNotSet()
  162.                             ->children()
  163.                                 ->scalarNode('template')->defaultValue('@FOSUser/Resetting/email.txt.twig')->end()
  164.                                 ->arrayNode('from_email')
  165.                                     ->canBeUnset()
  166.                                     ->children()
  167.                                         ->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
  168.                                         ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()
  169.                                     ->end()
  170.                                 ->end()
  171.                             ->end()
  172.                         ->end()
  173.                         ->arrayNode('form')
  174.                             ->addDefaultsIfNotSet()
  175.                             ->children()
  176.                                 ->scalarNode('type')->defaultValue(Type\ResettingFormType::class)->end()
  177.                                 ->scalarNode('name')->defaultValue('fos_user_resetting_form')->end()
  178.                                 ->arrayNode('validation_groups')
  179.                                     ->prototype('scalar')->end()
  180.                                     ->defaultValue(array('ResetPassword''Default'))
  181.                                 ->end()
  182.                             ->end()
  183.                         ->end()
  184.                     ->end()
  185.                 ->end()
  186.             ->end();
  187.     }
  188.     /**
  189.      * @param ArrayNodeDefinition $node
  190.      */
  191.     private function addChangePasswordSection(ArrayNodeDefinition $node)
  192.     {
  193.         $node
  194.             ->children()
  195.                 ->arrayNode('change_password')
  196.                     ->addDefaultsIfNotSet()
  197.                     ->canBeUnset()
  198.                     ->children()
  199.                         ->arrayNode('form')
  200.                             ->addDefaultsIfNotSet()
  201.                             ->children()
  202.                                 ->scalarNode('type')->defaultValue(Type\ChangePasswordFormType::class)->end()
  203.                                 ->scalarNode('name')->defaultValue('fos_user_change_password_form')->end()
  204.                                 ->arrayNode('validation_groups')
  205.                                     ->prototype('scalar')->end()
  206.                                     ->defaultValue(array('ChangePassword''Default'))
  207.                                 ->end()
  208.                             ->end()
  209.                         ->end()
  210.                     ->end()
  211.                 ->end()
  212.             ->end();
  213.     }
  214.     /**
  215.      * @param ArrayNodeDefinition $node
  216.      */
  217.     private function addServiceSection(ArrayNodeDefinition $node)
  218.     {
  219.         $node
  220.             ->addDefaultsIfNotSet()
  221.             ->children()
  222.                 ->arrayNode('service')
  223.                     ->addDefaultsIfNotSet()
  224.                         ->children()
  225.                             ->scalarNode('mailer')->defaultValue('fos_user.mailer.default')->end()
  226.                             ->scalarNode('email_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()
  227.                             ->scalarNode('token_generator')->defaultValue('fos_user.util.token_generator.default')->end()
  228.                             ->scalarNode('username_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()
  229.                             ->scalarNode('user_manager')->defaultValue('fos_user.user_manager.default')->end()
  230.                         ->end()
  231.                     ->end()
  232.                 ->end()
  233.             ->end();
  234.     }
  235.     /**
  236.      * @param ArrayNodeDefinition $node
  237.      */
  238.     private function addGroupSection(ArrayNodeDefinition $node)
  239.     {
  240.         $node
  241.             ->children()
  242.                 ->arrayNode('group')
  243.                     ->canBeUnset()
  244.                     ->children()
  245.                         ->scalarNode('group_class')->isRequired()->cannotBeEmpty()->end()
  246.                         ->scalarNode('group_manager')->defaultValue('fos_user.group_manager.default')->end()
  247.                         ->arrayNode('form')
  248.                             ->addDefaultsIfNotSet()
  249.                             ->fixXmlConfig('validation_group')
  250.                             ->children()
  251.                                 ->scalarNode('type')->defaultValue(Type\GroupFormType::class)->end()
  252.                                 ->scalarNode('name')->defaultValue('fos_user_group_form')->end()
  253.                                 ->arrayNode('validation_groups')
  254.                                     ->prototype('scalar')->end()
  255.                                     ->defaultValue(array('Registration''Default'))
  256.                                 ->end()
  257.                             ->end()
  258.                         ->end()
  259.                     ->end()
  260.                 ->end()
  261.             ->end();
  262.     }
  263. }