Configuration.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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 Sonata\UserBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  12. use Symfony\Component\Config\Definition\ConfigurationInterface;
  13. /**
  14. * This is the class that validates and merges configuration from your app/config files
  15. *
  16. * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
  17. */
  18. class Configuration implements ConfigurationInterface
  19. {
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function getConfigTreeBuilder()
  24. {
  25. $treeBuilder = new TreeBuilder();
  26. $rootNode = $treeBuilder->root('sonata_user');
  27. $supportedManagerTypes = array('orm', 'mongodb');
  28. $rootNode
  29. ->children()
  30. ->booleanNode('security_acl')->defaultValue(false)->end()
  31. ->arrayNode('table')
  32. ->addDefaultsIfNotSet()
  33. ->children()
  34. ->scalarNode('user_group')->defaultValue('fos_user_user_group')->end()
  35. ->end()
  36. ->end()
  37. ->scalarNode('impersonating_route')->defaultValue('homepage')->end()
  38. ->arrayNode('google_authenticator')
  39. ->addDefaultsIfNotSet()
  40. ->children()
  41. ->scalarNode('server')->cannotBeEmpty()->end()
  42. ->scalarNode('enabled')->defaultValue(false)->end()
  43. ->end()
  44. ->end()
  45. ->scalarNode('manager_type')
  46. ->defaultValue('orm')
  47. ->validate()
  48. ->ifNotInArray($supportedManagerTypes)
  49. ->thenInvalid('The manager type %s is not supported. Please choose one of '.json_encode($supportedManagerTypes))
  50. ->end()
  51. ->end()
  52. ->arrayNode('class')
  53. ->children()
  54. ->scalarNode('group')->end()
  55. ->scalarNode('user')->end()
  56. ->end()
  57. ->end()
  58. // Original code from the FOS User Bundle
  59. ->arrayNode('profile')
  60. ->addDefaultsIfNotSet()
  61. ->canBeUnset()
  62. ->children()
  63. ->arrayNode('form')
  64. ->addDefaultsIfNotSet()
  65. ->children()
  66. ->scalarNode('type')->defaultValue('sonata_user_profile')->end()
  67. ->scalarNode('handler')->defaultValue('sonata.user.profile.form.handler.default')->end()
  68. ->scalarNode('name')->defaultValue('sonata_user_profile_form')->cannotBeEmpty()->end()
  69. ->arrayNode('validation_groups')
  70. ->prototype('scalar')->end()
  71. ->defaultValue(array('Profile', 'Default'))
  72. ->end()
  73. ->end()
  74. ->end()
  75. ->end()
  76. ->end()
  77. ->end()
  78. ;
  79. return $treeBuilder;
  80. }
  81. }