Guest User

Untitled

a guest
Dec 5th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. namespace AppBundleDataFixturesORM;
  2.  
  3. use DoctrineCommonDataFixturesFixtureInterface;
  4. use DoctrineCommonPersistenceObjectManager;
  5. use SymfonyComponentDependencyInjectionContainerAwareInterface;
  6. use SymfonyComponentDependencyInjectionContainerInterface;
  7.  
  8. class LoadUserData implements FixtureInterface, ContainerAwareInterface {
  9.  
  10. private $container;
  11.  
  12. /**
  13. * Load data fixtures with the passed EntityManager
  14. *
  15. * @param ObjectManager $manager
  16. */
  17. public function load(ObjectManager $manager)
  18. {
  19. $user = new User();
  20. $user->setLogin('admin');
  21. $user->setEmail('admin@admin.admin');
  22. $encoder = $this->container->get('security.password_encoder');
  23. $password = $encoder->encodePassword($user, '123qwe');
  24. $user->setPassword($password);
  25.  
  26. $manager->persist();
  27. $manager->flush();
  28. }
  29.  
  30. public function setContainer(ContainerInterface $container = null)
  31. {
  32. $this->container = $container;
  33. }
  34. }
  35.  
  36. namespace AppBundleDataFixturesORM;
  37.  
  38. use DoctrineCommonDataFixturesFixtureInterface;
  39. use DoctrineCommonPersistenceObjectManager;
  40. use SymfonyComponentDependencyInjectionContainerAwareInterface;
  41. use SymfonyComponentDependencyInjectionContainerInterface;
  42.  
  43. class LoadUserData implements FixtureInterface, ContainerAwareInterface {
  44.  
  45. private $container;
  46.  
  47. /**
  48. * Load data fixtures with the passed EntityManager
  49. *
  50. * @param ObjectManager $manager
  51. */
  52. public function load(ObjectManager $manager)
  53. {
  54. $user = new User();
  55. $user->setLogin('admin');
  56. $user->setEmail('admin@admin.admin');
  57. $encoder = $this->container->get('security.password_encoder');
  58. $password = $encoder->encodePassword($user, '123qwe');
  59. $user->setPassword($password);
  60.  
  61. $manager->persist();
  62. $manager->flush();
  63. }
  64.  
  65. public function setContainer(ContainerInterface $container = null)
  66. {
  67. $this->container = $container;
  68. }
  69. }
  70.  
  71. parameters:
  72.  
  73. services:
  74. _defaults:
  75. autowire: true
  76. autoconfigure: true
  77. public: false
  78.  
  79. AppBundle:
  80. resource: '../../src/AppBundle/*'
  81. exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
  82.  
  83. AppBundleController:
  84. resource: '../../src/AppBundle/Controller'
  85. public: true
  86. tags: ['controller.service_arguments']
Add Comment
Please, Sign In to add comment