EntityFactory.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
  12. use Symfony\Component\Config\Definition\Builder\NodeDefinition;
  13. use Symfony\Component\DependencyInjection\ChildDefinition;
  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(string $key, string $providerId)
  26. {
  27. $this->key = $key;
  28. $this->providerId = $providerId;
  29. }
  30. public function create(ContainerBuilder $container, string $id, array $config)
  31. {
  32. $container
  33. ->setDefinition($id, new ChildDefinition($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')
  48. ->isRequired()
  49. ->info('The full entity class name of your user class.')
  50. ->cannotBeEmpty()
  51. ->end()
  52. ->scalarNode('property')->defaultNull()->end()
  53. ->scalarNode('manager_name')->defaultNull()->end()
  54. ->end()
  55. ;
  56. }
  57. }