em = $em; $this->domainName = $domainName; } public static function getSubscribedEvents() { return [ // when a user register using the normal form FOSUserEvents::REGISTRATION_COMPLETED => 'createAccount', // when we manually create a user using the command line // OR when we create it from the config UI FOSUserEvents::USER_CREATED => 'createAccount', ]; } public function createAccount(UserEvent $event) { $user = $event->getUser(); $account = new Account(); $account->setUser($user) ->setUsername($user->getUsername()) ->setServer($this->domainName); $this->em->persist($account); $user->setAccount($account); $this->em->persist($user); $this->em->flush(); } }