FOS\UserBundle\Command\CreateUserCommand::interact PHP Method

interact() protected method

See also: Command
protected interact ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function interact(InputInterface $input, OutputInterface $output)
    {
        if (!$input->getArgument('username')) {
            $username = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a username:', function ($username) {
                if (empty($username)) {
                    throw new \Exception('Username can not be empty');
                }
                return $username;
            });
            $input->setArgument('username', $username);
        }
        if (!$input->getArgument('email')) {
            $email = $this->getHelper('dialog')->askAndValidate($output, 'Please choose an email:', function ($email) {
                if (empty($email)) {
                    throw new \Exception('Email can not be empty');
                }
                return $email;
            });
            $input->setArgument('email', $email);
        }
        if (!$input->getArgument('password')) {
            $password = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a password:', function ($password) {
                if (empty($password)) {
                    throw new \Exception('Password can not be empty');
                }
                return $password;
            });
            $input->setArgument('password', $password);
        }
    }

Usage Example

Example #1
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     parent::interact($input, $output);
     if (!$input->getArgument('firstname')) {
         $firstname = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a firstname:', function ($firstname) {
             if (empty($firstname)) {
                 throw new \Exception('Firstname can not be empty');
             }
             return $firstname;
         });
         $input->setArgument('firstname', $firstname);
     }
     if (!$input->getArgument('lastname')) {
         $lastname = $this->getHelper('dialog')->askAndValidate($output, 'Please choose a lastname:', function ($lastname) {
             if (empty($lastname)) {
                 throw new \Exception('Lastname can not be empty');
             }
             return $lastname;
         });
         $input->setArgument('lastname', $lastname);
     }
     if (!$input->getArgument('enterprise')) {
         $enterprise = $this->getHelper('dialog')->askAndValidate($output, 'Please choose an enterprise:', function ($enterprise) {
             if (empty($enterprise)) {
                 throw new \Exception('Enterprise can not be empty');
             }
             return $enterprise;
         });
         $input->setArgument('enterprise', $enterprise);
     }
 }
All Usage Examples Of FOS\UserBundle\Command\CreateUserCommand::interact