コード例 #1
0
ファイル: MemberListener.php プロジェクト: sfriel/fol
 public function prePersist(Member $member, LifecycleEventArgs $event)
 {
     /** @var UserManager $userManager */
     $userManager = $this->container->get('fos_user.user_manager');
     /** @var \AppBundle\Entity\User $user */
     $user = $userManager->findUserByUsername($member->getUserName());
     if ($user === null) {
         $user = $userManager->createUser();
         $user->setUsername($member->getUserName());
         $user->setEmail($member->getEmail());
         $user->setRoles(['ROLE_USER']);
         $user->setPlainPassword('welcome');
         $user->setEnabled(true);
         $userManager->updateUser($user, true);
     }
     $member->setFosUser($user);
 }