EntityFactory.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Bridge\Doctrine\DependencyInjection\Security\UserProvider;
  11. use Symfony\Component\Config\Definition\Builder\NodeDefinition;
  12. use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
  13. use Symfony\Component\DependencyInjection\DefinitionDecorator;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. /**
  16. * EntityFactory creates services for Doctrine user provider.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. * @author Christophe Coevoet <stof@notk.org>
  20. */
  21. class EntityFactory implements UserProviderFactoryInterface
  22. {
  23. private $key;
  24. private $providerId;
  25. public function __construct($key, $providerId)
  26. {
  27. $this->key = $key;
  28. $this->providerId = $providerId;
  29. }
  30. public function create(ContainerBuilder $container, $id, $config)
  31. {
  32. $container
  33. ->setDefinition($id, new DefinitionDecorator($this->providerId))
  34. ->addArgument($config['class'])
  35. ->addArgument($config['property'])
  36. ->addArgument($config['manager_name'])
  37. ;
  38. }
  39. public function getKey()
  40. {
  41. return $this->key;
  42. }
  43. public function addConfiguration(NodeDefinition $node)
  44. {
  45. $node
  46. ->children()
  47. ->scalarNode('class')->isRequired()->cannotBeEmpty()->end()
  48. ->scalarNode('property')->defaultNull()->end()
  49. ->scalarNode('manager_name')->defaultNull()->end()
  50. ->end()
  51. ;
  52. }
  53. }