Load information for admin user form CLI options or ask info to user.

@param InputInterface $input
@param OutputInterface $output
@return array
515719
protected function getAdminInformation(InputInterface $input, OutputInterface $output)
    {
        $admin = array();

        /**
         * @var \Symfony\Component\Console\Helper\DialogHelper
         */
        $dialog = $this->getHelperSet()->get('dialog');

        // Function to validate mail address.
        $mailValidator = function ($answer) {
            if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
                throw new \InvalidArgumentException(Lang::get('must_be_valid_email'));
            }

            return $answer;
        };

        if ($adminEmail = $input->getOption('admin-mail')) {
            $adminEmail = $mailValidator($adminEmail);
        } else {
            $adminEmail = $dialog->askAndValidate($output, Lang::get('enter_email'), $mailValidator, false);
        }
        if (!$adminName = $input->getOption('admin-name')) {
            $adminName = $dialog->ask($output, Lang::get('enter_name'));
        }
        if (!$adminPass = $input->getOption('admin-pass')) {
            $adminPass = $dialog->askHiddenResponse($output, Lang::get('enter_password'));
        }

        $admin['mail'] = $adminEmail;
        $admin['name'] = $adminName;
        $admin['pass'] = $adminPass;

        return $admin;
    }
945458
protected function initialize(Input $input, Output $output) {
        return $this->cmd->initialize($input,$output);
    }
10580
protected function execute(InputInterface $input, OutputInterface $output)
	{
		$output->writeln([ // outputs multiple lines to the console (adding "\n" at the end of each line)
			'MyAdmin DocBlock Parser',
			'=======================',
			''
						 ]);
		$output->writeln('<info>foo</info>'); // green text
		$output->writeln('<comment>foo</comment>'); // yellow text
		$output->writeln('<question>foo</question>'); // black text on a cyan background
		$output->writeln('<error>foo</error>'); // white text on a red background
		$formatter = $this->getHelper('formatter');
		// Section - [SomeSection] Here is some message related to that section
		$formattedLine = $formatter->formatSection('SomeSection', 'Here is some message related to that section');
		$output->writeln($formattedLine);
		// Error Block
		$errorMessages = ['Error!', 'Something went wrong'];
		$formattedBlock = $formatter->formatBlock($errorMessages, 'error');
		$output->writeln($formattedBlock);

		$paths = ['include', 'scripts'];
		$calls = [
			'getFiles'      => ['getHash', 'getSource', 'getNamespaces', 'getIncludes', 'getConstants', 'getFunctions', 'getInterfaces', 'getTraits', 'getPath', 'getDocBlock', 'getName'],
			'getNamespaces' => ['getClasses', 'getConstants', 'getFunctions', 'getInterfaces', 'getTraits', 'getFqsen', 'getName'],
			'getClasses'    => ['isFinal', 'isAbstract', 'getParent', 'getInterfaces', 'getConstants', 'getMethods', 'getProperties', 'getUsedTraits', 'getFqsen', 'getName', 'getDocBlock'],
			'getMethods'    => ['isAbstract', 'isFinal', 'isStatic', 'getVisibility', 'getArguments', 'getFqsen', 'getName', 'getDocBlock'],
			'getProperties' => ['isStatic', 'getDefault', 'getTypes', 'getVisibility', 'getFqsen', 'getName', 'getDocBlock'],
			'getTraits'     => ['getMethods', 'getProperties', 'getUsedTraits', 'getFqsen', 'getName', 'getDocBlock'],
			'getInterfaces' => ['getParents', 'getConstants', 'getMethods', 'getFqsen', 'getName', 'getDocBlock'],
			'getArguments'  => ['isByReference', 'isVariadic', 'getName', 'getTypes', 'getDefault'],
			'getFunctions'  => ['getArguments', 'getFqsen', 'getName', 'getDocBlock'],
			'getConstants'  => ['getValue', 'getFqsen', 'getName', 'getDocBlock']
		];
		/**
		 * @param $parent
		 * @param $call
		 * @param $calls
		 * @return array
		 */
		function do_call($parent, $call, $calls)
		{
			echo "Running \$parent->$call();".PHP_EOL;
			$response = $parent->$call();
			if (isset($calls[$call])) {
				$out = [];
				/** @var \phpDocumentor\Reflection\Php\File $file */
				foreach ($response as $idx => $child) {
					foreach ($calls[$call] as $childCall) {
						/** @var \phpDocumentor\Reflection\Php\File $file */
						$out[$idx] = $childResponse = $child->$childCall();
					}
				}
				echo "Running \$child->$childCall();".PHP_EOL;
				return $out;
			} else {
				return $response;
			}
		}

		$projectFactory = \phpDocumentor\Reflection\Php\ProjectFactory::createInstance();
		$files = [];
		$map = [];
		foreach ($paths as $path) {
			$files[] = new \phpDocumentor\Reflection\File\LocalFile(__DIR__.'/../../../../../'.$path);
		}
		/** @var Project $project */
		$project = $projectFactory->create('MyProject', $files);
		$map = do_call($project, 'getFiles', $calls);
		file_put_contents(__DIR__.'/../../../../../include/config/parse.serial', serialize($map));
		file_put_contents(__DIR__.'/../../../../../include/config/parse.json', json_encode($map, JSON_PRETTY_PRINT));
		/** @var \phpDocumentor\Reflection\Php\Class_ $class */
		/* foreach ($file->getClasses() as $class)
			echo '- ' . $class->getFqsen() . PHP_EOL;
		} */
		/** @var \phpDocumentor\Reflection\Php\Function_ $function */
		/* foreach ($file->getFunctions() as $function) {
			echo '- ' . $function->getFqsen() . PHP_EOL;
		} */

		/** DocBlock / Reflection Parsing
		 * Reconstituting a docblock - https://github.com/phpDocumentor/ReflectionDocBlock/blob/master/examples/03-reconstituting-a-docblock.php
		 * Adding Your own Tag - https://github.com/phpDocumentor/ReflectionDocBlock/blob/master/examples/04-adding-your-own-tag.php
		 */

		/*
		$class = new ReflectionClass('MyClass');
		$phpdoc = new \phpDocumentor\Reflection\DocBlock($class);

		var_dump($phpdoc->getShortDescription());
		var_dump($phpdoc->getLongDescription()->getContents());
		var_dump($phpdoc->getTags());
		var_dump($phpdoc->hasTag('author'));
		var_dump($phpdoc->hasTag('copyright'));
		// But we can also grab all tags of a specific type, such as `see`
		$seeTags = $docblock->getTagsByName('see');

		$reflector = new ReflectionClass('Example');
		// to get the Class DocBlock
		echo $reflector->getDocComment();
		// to get the Method DocBlock
		$reflector->getMethod('fn')->getDocComment();
		*/
	}
665599
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $userService = new UserService($this->userStore);

        /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
        $dialog = $this->getHelperSet()->get('dialog');

        // Function to validate mail address.
        $mailValidator = function ($answer) {
            if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
                throw new \InvalidArgumentException(Lang::get('must_be_valid_email'));
            }

            return $answer;
        };

        $adminEmail = $dialog->askAndValidate($output, Lang::get('enter_email'), $mailValidator, false);
        $adminName = $dialog->ask($output, Lang::get('enter_name'));
        $adminPass = $dialog->askHiddenResponse($output, Lang::get('enter_password'));

        try {
            $userService->createUser($adminName, $adminEmail, $adminPass, true);
            $output->writeln(Lang::get('user_created'));
        } catch (\Exception $e) {
            $output->writeln(sprintf('<error>%s</error>', Lang::get('failed_to_create')));
            $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
        }
    }
1288163
protected function interact(InputInterface $input, OutputInterface $output)
    {
        $console = $this->getHelper('question');

        $output->writeln(
            [
                '',
                'This command will create a <info>user</info> for <comment>Shuwee admin</comment>',
                '',
            ]
        );

        // Username
        $username = null;
        try {
            $username = $input->getArgument('username') ? $this->usernameValidator(
                $input->getArgument('username')
            ) : null;
        } catch (\Exception $error) {
            $output->writeln($console->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
        }

        if (null === $username) {
            $question = new Question('<info>Username</info>: ');
            $question->setValidator([$this, 'usernameValidator']);
            $question->setMaxAttempts(self::MAX_ATTEMPTS);
            $username = $console->ask($input, $output, $question);
            $input->setArgument('username', $username);
        } else {
            $output->writeln('<info>Username</info>: '.$username);
        }

        // Password
        $password = null;
        try {
            $password = $input->getArgument('password') ? $this->passwordValidator(
                $input->getArgument('password')
            ) : null;
        } catch (\Exception $error) {
            $output->writeln($console->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
        }

        if (null === $password) {
            $question = new Question('<info>Password</info> (your type will be hidden): ');
            $question->setValidator([$this, 'passwordValidator']);
            $question->setHidden(true);
            $question->setMaxAttempts(self::MAX_ATTEMPTS);
            $password = $console->ask($input, $output, $question);
            $input->setArgument('password', $password);
        } else {
            $output->writeln('<info>Password</info>: '.str_repeat('*', strlen($password)));
        }

        $output->writeln('');
    }
952891
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('<info>Following strategies to extract an authentication key are available:</info>');
        $output->writeln(
            "<info>\t* " .
            implode(PHP_EOL . "\t* ", $this->strategies) .
            "</info>"
        );
    }
976113
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->bootstrap($input, $output);

        $environment = $input->getOption('environment');
        $format = $input->getOption('format');

        if ($environment === null) {
            $environment = $this->getConfig()->getDefaultEnvironment();
            $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment);
        } else {
            $output->writeln('<info>using environment</info> ' . $environment);
        }
        if ($format !== null) {
            $output->writeln('<info>using format</info> ' . $format);
        }

        $output->writeln('<info>ordering by </info>' . $this->getConfig()->getVersionOrder() . " time");

        // print the status
        return $this->getManager()->printStatus($environment, $format);
    }
1109651
protected function initialize(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->output = $output;
        $this->formatter = $this->getHelper('formatter');
        $this->fs = new Filesystem();
    }
1293282
private function askForPropertyOptions(InputInterface $input, OutputInterface $output)
    {
        $output->writeln(
            "\n"
                . '<info>Enter property options, for example <comment>"index"="not_analyzed"</comment>'
                . ' allows mapper to index this field, so it is searchable, but value will be not analyzed.</info>'
        );

        return $this->questionHelper->ask(
            $input,
            $output,
            $this->getQuestion(
                'Property options [<comment>press <info><return></info> to stop</comment>]',
                false,
                null,
                ['"index"="not_analyzed"', '"analyzer"="standard"']
            )
        );
    }
143350
private function askForCustomResources(InputInterface $input, OutputInterface $output) {
        $question = new Question(
            'Which custom resources should the public key have access to?' . PHP_EOL .
            '(comma-separated) '
        );

        $question->setValidator(function($answer) {
            $resources = array_filter(array_map('trim', explode(',', $answer)));

            if (empty($resources)) {
                throw new RuntimeException(
                    'You must specify at least one resource'
                );
            }

            return $resources;
        });

        return $this->getHelper('question')->ask($input, $output, $question);
    }
324683
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($root = $input->getArgument('root-dir')) {
            chdir(realpath($root));
        }

        $rootDir = realpath(getcwd());
        $logger  = new ConsoleLogger($output);

        $composerJson = $rootDir . '/composer.json';
        if (!file_exists($composerJson)) {
            $logger->error(
                '<error>File not found, can not analyze: {file}</error> ',
                array('file' => $composerJson)
            );

            return 1;
        }

        $destinations   = array();
        $destinations[] = new PsrLogDestination($logger);

        $report   = $this->prepareReport($input, $logger);
        $composer = json_decode(file_get_contents($composerJson), true);
        $ignore   = $this->getIgnoredFiles($composer, $input->getOption('ignore-files'));
        $factory  = new AutoloadValidatorFactory($rootDir, new ClassMapGenerator($ignore), $report);
        $test     = new AutoloadValidator($factory->createFromComposerJson($composer), $report);
        $test->validate();
        if ($report->hasError()) {
            $logger->error('<error>Testing loaders found errors</error> ');
        }

        $enumLoader = new EnumeratingClassLoader();
        $this->prepareLoader($enumLoader, $test);

        $hacker = new HackPreparator($enumLoader, $logger);
        if ($custom = $input->getOption('add-autoloader')) {
            $hacker->prepareHacks(
                $custom,
                array(
                    $rootDir,
                    dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'hacks'
                )
            );
        }
        $this->prepareComposerFallbackLoader($enumLoader, $rootDir, $composer);
        if (!($input->getOption('disable-legacy-hacks') || $input->getOption('add-autoloader'))) {
            $hacker->prepareLegacyHack();
        }

        $loadCycle = new AllLoadingAutoLoader($enumLoader, $test->getClassMap(), $logger);

        return static::$exitCodes[$loadCycle->run() && !$report->hasError()];
    }
1015557
protected function interact(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $io->title('Welcome to the VinceT Admin generator');

        if (!$input->getArgument('name')) {
            while (!$this->metadata) {
                $question = new Question('Enter the model for admin generation');
                $name = $io->askQuestion($question);
                $input->setArgument('name', $name);
                try {
                    $this->metadata = $this->retrieveMetadatas($name);
                } catch (\Exception $e) {
                    $io->error($e->getMessage());
                }
            }
        }
    }
1372739
protected function waitForUserInput(InputInterface $input, OutputInterface $output)
    {
        $helper   = $this->getHelper('question');
        $question = new Question('<info>You > </info>');

        $message = $helper->ask($input, $output, $question);

        $this->listenForConsoleCommands($input, $output, $message);

        $this->getBotResponse($input, $output, $message);
    }
642598
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->modx = $this->console->loadMODX();
        $this->modx->cacheManager->refresh();
        $output->writeln('### Cache has been refreshed(cleared) ###');
    }
1062771
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $cmd        = $input->getArgument('cmd');
        $process    = $input->getArgument('server');

        $server = new Server(
            Config::get('name'),
            $process
        );

        $server->$cmd();
    }
753601
private function askForSpecificResources(InputInterface $input, OutputInterface $output) {
        $resources = Resource::getAllResources();
        sort($resources);

        $question = new ChoiceQuestion(
            'Which resources should the public key have access to? (comma-separated) ',
            $resources
        );
        $question->setMultiselect(true);

        return $this->getHelper('question')->ask($input, $output, $question);
    }
421517
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (null === $this->em) {
            $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
            $this->groupManager = $this->getContainer()->get('fos_user.group_manager');
            $this->userClassname = $this->getContainer()->getParameter('fos_user.model.user.class');
            $this->defaultLocale = $this->getContainer()->getParameter('kunstmaan_admin.default_admin_locale');
        }

        $username = $input->getArgument('username');
        $email = $input->getArgument('email');
        $password = $input->getArgument('password');
        $locale = $input->getArgument('locale');
        $superAdmin = $input->getOption('super-admin');
        $inactive = $input->getOption('inactive');
        $groupOption = $input->getOption('group');

        if (null === $locale) {
            $locale = $this->defaultLocale;
        }
        $command = $this->getApplication()->find('fos:user:create');
        $arguments = array(
            'command' => 'fos:user:create',
            'username' => $username,
            'email' => $email,
            'password' => $password,
            '--super-admin' => $superAdmin,
            '--inactive' => $inactive,
        );

        $input = new ArrayInput($arguments);
        $command->run($input, $output);

        // Fetch user that was just created
        $user = $this->em->getRepository($this->userClassname)->findOneBy(array('username' => $username));

        // Attach groups
        $groupOutput = [];

        foreach (explode(',', $groupOption) as $groupId) {
            if ((int) $groupId === 0) {
                foreach ($this->groups as $value) {
                    if ($groupId === $value->getName()) {
                        $group = $value;

                        break;
                    }
                }
            } else {
                $group = $this->groups[$groupId];
            }

            if (isset($group) && $group instanceof Group) {
                $groupOutput[] = $group->getName();
                $user->getGroups()->add($group);
            } else {
                throw new \RuntimeException(
                    'The selected group(s) can\'t be found.'
                );
            }
        }

        // Set admin interface locale and enable password changed
        $user->setAdminLocale($locale);
        $user->setPasswordChanged(true);

        // Persist
        $this->em->persist($user);
        $this->em->flush();

        $output->writeln(sprintf('Added user <comment>%s</comment> to groups <comment>%s</comment>', $input->getArgument('username'), implode(',', $groupOutput)));
    }