1 <?php 
declare(strict_types
=1); 
   4  * This file is part of the Rapsys UserBundle package. 
   6  * (c) Raphaël Gertz <symfony@rapsys.eu> 
   8  * For the full copyright and license information, please view the LICENSE 
   9  * file that was distributed with this source code. 
  12 namespace Rapsys\UserBundle\Fixture
; 
  14 use Doctrine\Bundle\FixturesBundle\Fixture
; 
  15 use Doctrine\Persistence\ObjectManager
; 
  17 use Rapsys\UserBundle\RapsysUserBundle
; 
  19 use Symfony\Component\DependencyInjection\ContainerInterface
; 
  20 use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface
; 
  25 class UserFixture 
extends Fixture 
{ 
  29         private array $config; 
  32          * Air fixtures constructor 
  34         public function __construct(private ContainerInterface 
$container, private UserPasswordHasherInterface 
$hasher) { 
  36                 $this->config 
= $container->getParameter(RapsysUserBundle
::getAlias()); 
  42         public function load(ObjectManager 
$manager): void { 
  52                 foreach($civilityTree as $civilityData) { 
  53                         $civility = new $this->config
['class']['civility']($civilityData); 
  54                         $manager->persist($civility); 
  55                         $civilitys[$civilityData] = $civility; 
  60                 //XXX: ROLE_XXX is required by 
  69                 foreach($groupTree as $groupData) { 
  70                         $group = new $this->config
['class']['group']($groupData); 
  71                         $manager->persist($group); 
  72                         $groups[$groupData] = $group; 
  76                 //Flush to get the ids 
  82                                 'civility' => 'Mister', 
  84                                 'mail' => 'contact@example.com', 
  85                                 'forename' => 'Forename', 
  86                                 'surname' => 'Surname', 
  94                 foreach($userTree as $userData) { 
  95                         $user = new $this->config
['class']['user']($userData['mail'], $userData['password'], $civilitys[$userData['civility']], $userData['forename'], $userData['surname'], $userData['active']); 
  96                         //XXX: required to store a hashed password 
  97                         $user->setPassword($this->hasher
->hashPassword($user, $userData['password'])); 
  98                         $user->addGroup($groups[$userData['group']]); 
  99                         $manager->persist($user); 
 104                 //Flush to get the ids