コード例 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getDialogHelper();
     $root = $this->getRoot();
     if ($root === null) {
         foreach (array('username', 'email', 'password') as $option) {
             if ($input->getOption($option) === null) {
                 throw new \RuntimeException(sprintf('The %s option must be provided.', $option));
             }
         }
     }
     $action = $root ? 'reset' : 'creation';
     if ($input->isInteractive() && !$input->getOption('silent')) {
         if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm ' . $action, 'yes', '?'), true)) {
             return 1;
         }
     }
     if (!$root) {
         $root = new User();
         $root->setId(1);
     }
     if ($input->getOption('username') !== null) {
         //TODO: Validate, use same validator as in the askAndValidate below
         $root->setUsername($input->getOption('username'));
     }
     if ($input->getOption('email') !== null) {
         //TODO: Validate, use same validator as in the askAndValidate below
         $root->setEmail($input->getOption('email'));
     }
     if ($input->getOption('email') !== null) {
         //TODO: Validate, use same validator as in the askAndValidate below
         $helper = new UserHelper($this->getContainer());
         $helper->setPassword($root, $input->getOption('password'));
     }
     $em = $this->getContainer()->get('doctrine')->getManager();
     $em->persist($root);
     $em->flush();
     $output->writeln(array('', 'The root is now usable. Have fun!', ''));
 }
コード例 #2
0
ファイル: Group.php プロジェクト: mapbender/fom
 /**
  * Add users
  *
  * @param FOM\UserBundle\Entity\User $users
  * @return Group
  */
 public function addUser(\FOM\UserBundle\Entity\User $user)
 {
     $this->users[] = $user;
     $user->addGroup($this);
     return $this;
 }