Autocompletes a question.

@param OutputInterface $output
@param FileFilter $filter
@param $inputStream

@return string
556274
private function autocomplete(OutputInterface $output, FileFilter $filter, $inputStream)
    {
        $autocomplete = $filter->getResultFor($filter->getDefault());
        $ret = $filter->getDefault();

        $i = strlen($ret);
        $ofs = 0;
        $matches = $autocomplete;
        $numMatches = count($matches);

        $sttyMode = shell_exec('stty -g');

        // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
        shell_exec('stty -icanon -echo');

        // Add highlighted text style
        $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white'));

        $output->write($ret);
        $this->searchCompletion($ret, $filter, $ofs, $matches, $numMatches);
        $this->displaySuggestion($output, $matches, $numMatches, $ofs, $i);

        // Read a keypress
        while (!feof($inputStream)) {
            $c = fread($inputStream, 1);

            // Backspace Character
            if ("\177" === $c) {
                if (0 === $numMatches && 0 !== $i) {
                    $i--;
                    // Move cursor backwards
                    $output->write("\033[1D");
                }

                if ($i === 0) {
                    $ofs = -1;
                    $matches = $filter->getResultFor($ret);
                    $numMatches = count($matches);
                } else {
                    $matches = array();
                    $numMatches = 0;
                }

                // Pop the last character off the end of our string
                $ret = substr($ret, 0, $i);
            } elseif ("\033" === $c) {
                // Did we read an escape sequence?
                $c .= fread($inputStream, 2);

                // A = Up Arrow. B = Down Arrow
                if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) {
                    if ('A' === $c[2] && -1 === $ofs) {
                        $ofs = 0;
                    }

                    if (0 === $numMatches) {
                        continue;
                    }

                    $ofs += ('A' === $c[2]) ? -1 : 1;
                    $ofs = ($numMatches + $ofs) % $numMatches;
                }
            } elseif (ord($c) < 32) {
                if ("\t" === $c || "\n" === $c) {
                    if ($numMatches > 0 && -1 !== $ofs) {
                        $ret = $matches[$ofs];
                        // Echo out remaining chars for current match
                        $output->write(substr($ret, $i));
                        $i = strlen($ret);
                        $this->searchCompletion($ret, $filter, $ofs, $matches, $numMatches);
                    }

                    if ("\n" === $c) {
                        $output->write($c);
                        break;
                    }

                    //$numMatches = 0;
                }
                if ("\t" !== $c) {
                    //continue;
                }
            } else {
                $output->write($c);
                $ret .= $c;
                $i++;
                $this->searchCompletion($ret, $filter, $ofs, $matches, $numMatches);
            }

            $this->displaySuggestion($output, $matches, $numMatches, $ofs, $i);
        }

        // Reset stty so it behaves normally again
        shell_exec(sprintf('stty %s', $sttyMode));

        return $ret;
    }
146586
public static function toProtobuf($object, $filter = NULL)
	{
		$output = '';

		if (isset($object->namePart) && ($filter === null || isset($filter['namePart']))) {
			$output .= "\x0a";
			$output .= Binary::encodeVarint(strlen($object->namePart));
			$output .= $object->namePart;
		}

		if (isset($object->isExtension) && ($filter === null || isset($filter['isExtension']))) {
			$output .= "\x10";
			$output .= Binary::encodeVarint((int)$object->isExtension);
		}

		return $output;
	}
16399
public static function toProtobuf($object, $filter = NULL)
	{
		$output = '';

		if (isset($object->path) && ($filter === null || isset($filter['path']))) {
			$packedBuffer = '';
			$output .= "\x0a";
			foreach ($object->path instanceof \Traversable ? $object->path : (array)$object->path as $k => $v) {
				$packedBuffer .= Binary::encodeVarint($v);
			}
			$output .= Binary::encodeVarint(strlen($packedBuffer));
			$output .= $packedBuffer;
		}

		if (isset($object->span) && ($filter === null || isset($filter['span']))) {
			$packedBuffer = '';
			$output .= "\x12";
			foreach ($object->span instanceof \Traversable ? $object->span : (array)$object->span as $k => $v) {
				$packedBuffer .= Binary::encodeVarint($v);
			}
			$output .= Binary::encodeVarint(strlen($packedBuffer));
			$output .= $packedBuffer;
		}

		if (isset($object->leadingComments) && ($filter === null || isset($filter['leadingComments']))) {
			$output .= "\x1a";
			$output .= Binary::encodeVarint(strlen($object->leadingComments));
			$output .= $object->leadingComments;
		}

		if (isset($object->trailingComments) && ($filter === null || isset($filter['trailingComments']))) {
			$output .= "\x22";
			$output .= Binary::encodeVarint(strlen($object->trailingComments));
			$output .= $object->trailingComments;
		}

		if (isset($object->leadingDetachedComments) && ($filter === null || isset($filter['leadingDetachedComments']))) {
			foreach ($object->leadingDetachedComments instanceof \Traversable ? $object->leadingDetachedComments : (array)$object->leadingDetachedComments as $k => $v) {
				$output .= "\x32";
				$output .= Binary::encodeVarint(strlen($v));
				$output .= $v;
			}
		}

		return $output;
	}
189224
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!$this->apiHelper->restore($this->getHelper('question'), $input, $output)) {
            return;
        }

        $output->writeln(\sprintf('Checking for URL: <info>%s</info>', $this->getUrl()).PHP_EOL);

        /** @var QuestionHelper $asker */
        $asker = $this->getHelper('question');
        $user = $this->apiHelper->currentUser();

        $enabled = $this->getCallbackStatus($user);
        $question = new ConfirmationQuestion(
            sprintf(
                '%s [y/N]: ',
                $enabled
                    ? 'The callback is currently <info>ACTIVE</info>, would you like to disable?'
                    : 'The callback is currently <info>INACTIVE</info>, would you like to enable?'
            ),
            false
        );

        if (!$asker->ask($input, $output, $question)) {
            return;
        }

        try {
            if ($enabled) {
                $this->disableCallback($user);
            } else {
                $this->enableCallback($user);
            }

            $output->writeln('<info>New status successfully applied.</info>');
        } catch (BunqException $exception) {
            $output->writeln('<error>An error occured while applying new status: '.$exception->getMessage().'</error>');
        }
    }
1026910
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!$this->apiHelper->restore($this->getHelper('question'), $input, $output)) {
            return;
        }

        $bunqUser = $this->apiHelper->currentUser()->getBunqUser();

        /** @var Pointer $pointer */
        foreach ($bunqUser->getAlias() as $pointer) {
            $output->writeln(\sprintf('<info>%s</info>: %s', $pointer->getType(), $pointer->getValue()));
        }
    }
680168
public function merge(BaseInputFilter $inputFilter, $recursive = false)
    {
        foreach ($inputFilter->getInputs() as $name => $input) {
            $this->add($input, $name, $recursive);
        }

        if ($inputFilter instanceof InputFilterInterface) {
            $this->getFilterChain()->merge($inputFilter->getFilterChain());
            $this->getValidatorChain()->merge($inputFilter->getValidatorChain());
        }

        return $this;
    }
483843
protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var QuestionHelper $asker */
        $asker = $this->getHelper('question');

        // check for existence and possibly abort
        if (\file_exists($this->configurationFile)) {
            $question = new ConfirmationQuestion(
                'It looks like the configuration file already exists, do you want to overwrite? [y/N]: ',
                false
            );

            if (!$asker->ask($input, $output, $question)) {
                return;
            }
        }

        $output->writeln(sprintf('About to generate API context for environment: <info>%s</info>', $this->environment));

        try {
            $environmentType = new BunqEnumApiEnvironmentType($this->environment);
            $tempfile = tempnam(\sys_get_temp_dir(), 'bunq_');

            if (BunqEnumApiEnvironmentType::CHOICE_PRODUCTION === $this->environment) {
                $question = new Question('Please enter your bunq API key: ', null);
                do {
                    $apiKey = $asker->ask($input, $output, $question);
                } while (null === $apiKey);

                // will create production environment context with supplied application description
                $apiContext = ApiContext::create(
                    $environmentType,
                    $apiKey,
                    $this->applicationDescription,
                    $this->allowedIps
                );

                $apiContext->save($tempfile);
            } else {
                // will create sandbox environment context
                InstallationUtil::automaticInstall(
                    $environmentType,
                    $tempfile,
                    null
                );
            }

            $contents = \file_get_contents($tempfile);

            $output->writeln('Successfully connected to the bunq API, please provide a password to encrypt the configuration file with. Make it strong!');
            $this->apiHelper->store($contents, null, $input, $output, $asker);

            if (false === \unlink($tempfile)) {
                $output->writeln('<error>WARNING: </error> unable to delete temporary installation file, you really should delete this manually: '.$tempfile);
            } else {
                $output->writeln('<info>Success!</info>');
            }
        } catch (\Exception $e) {
            $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
        }
    }
665111
protected function verifyArguments(InputInterface $input, OutputInterface $output)
    {
        $type       = $input->getArgument('type');
        $validTypes = $this->getValidTypes();
        if ($type === null) {
            // ask a question and default $type='all'
            $helper   = $this->getHelper('question');
            $question = new ConfirmationQuestion('Do you want to clear all cache? [N] ', false);

            if (!$helper->ask($input, $output, $question)) {
                return false;
            }

            $type = 'all';
        }

        if (!in_array($type, $validTypes)) {
            $output->writeln(
                sprintf(
                    '<error>Type "%s" does not exist. Valid type are: %s.</error>',
                    $type,
                    implode(', ', $validTypes)
                )
            );

            return false;
        }

        if ($type === 'provider' && !$input->hasArgument('service')) {
            $output->writeln(
                '<error>When using type "provider" you must specify a service id for that provider.</error>'
            );
            $output->writeln('<error>Usage: php app/console cache:flush provider cache.provider.acme</error>');

            return false;
        }

        return $type;
    }
307038
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $align = $input->getOption('align') === Step::ALIGN_TO_LEFT
            ? Step::ALIGN_TO_LEFT
            : Step::ALIGN_TO_RIGHT;

        $directory = $input->getArgument('directory');
        $finder    = (new FeatureResolve($directory))->__invoke();

        $output->writeln("\nFinding files on <info>" . $directory . "</info>\n");

        /* @var $file \Symfony\Component\Finder\SplFileInfo */
        foreach ($finder as $file) {

            $fileContent            = $file->getContents();
            $contentWithoutComments = $this->removeComments($fileContent);
            $feature                = $this->parser->parse($fileContent);

            $formatted = (new ComposedFormatter(
                new FeatureDescription(),
                new Background($align),
                new Scenario($align),
                new Tags()
            ))
                ->__invoke($feature);

            if ($formatted !== $contentWithoutComments) {

                if (! defined('FAILED')) {
                    define('FAILED', true);
                }

                $diff = new Differ("--- Original\n+++ Expected\n", false);

                $output->writeln('<error>Wrong style: ' . $file->getRealPath() . '</error>');
                $output->writeln($diff->diff($contentWithoutComments, $formatted));
            }
        }

        if (defined('FAILED')) {
            return 1;
        }

        $output->writeln('<bg=green;fg=white>     Everything is OK!     </>');
    }
853340
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->output = $output;

        $this->arguments = $input->getArguments();
        $this->options = $input->getOptions();
        $this->stub = $this->getStub();

        if ($this->stub) {
            $this
                ->replaceFrequency()
                ->replaceConstraint()
                ->replaceCommand()
                ->replacePath()
                ->replaceDescription()
            ;
        }

        if ($this->save()) {
            $output->writeln('<info>The task file generated successfully</info>');
        } else {
            $output->writeln('<comment>There was a problem when generating the file. Please check your command.</comment>');
        }
    }
623294
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->output = $output;
        $outputFile = null;
        if ($file = $input->getOption('output-file')) {
            $outputFile = $file;
        }
        $this->service($input->getArgument($this->argument), $outputFile);
    }
709047
protected function execute(InputInterface $input, OutputInterface $output)
	{
		$output->writeln([ // outputs multiple lines to the console (adding "\n" at the end of each line)
			'User Creator',
			'============',
			''
						 ]);
		$output->writeln('Username: '.$input->getArgument('username')); // retrieve the argument value using getArgument()
		$output->write('You are about to '); // outputs a message without adding a "\n" at the end of the line
		$output->write('create a user.');

		/** Coloring
		 * @link http://symfony.com/doc/current/console/coloring.html
		 */
		$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

		/** Formatting
		 * @link http://symfony.com/doc/current/components/console/helpers/formatterhelper.html
		 */
		$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);
		// Truncated Messages
		$message = 'This is a very long message, which should be truncated';
		$truncatedMessage = $formatter->truncate($message, 7); // This is...
		$truncatedMessage = $formatter->truncate($message, 7, '!!'); // result: This is!!
		$output->writeln($truncatedMessage);

		/** Table
		 * @link http://symfony.com/doc/current/components/console/helpers/table.html
		 */

		/** Style
		 * @link http://symfony.com/doc/current/console/style.html
		 */

		/** Process Helper
		 * @link http://symfony.com/doc/current/components/console/helpers/processhelper.html
		 */
		/** Progress Bar
		 * @link http://symfony.com/doc/current/components/console/helpers/progressbar.html
		 */
		/** Question Helper
		 * @link http://symfony.com/doc/current/components/console/helpers/questionhelper.html
		 */
	}
1142411
public static function toProtobuf($object, $filter = NULL)
	{
		$output = '';

		if (isset($object->javaPackage) && ($filter === null || isset($filter['javaPackage']))) {
			$output .= "\x0a";
			$output .= Binary::encodeVarint(strlen($object->javaPackage));
			$output .= $object->javaPackage;
		}

		if (isset($object->javaOuterClassname) && ($filter === null || isset($filter['javaOuterClassname']))) {
			$output .= "\x42";
			$output .= Binary::encodeVarint(strlen($object->javaOuterClassname));
			$output .= $object->javaOuterClassname;
		}

		if (isset($object->javaMultipleFiles) && ($filter === null || isset($filter['javaMultipleFiles']))) {
			$output .= "\x50";
			$output .= Binary::encodeVarint((int)$object->javaMultipleFiles);
		}

		if (isset($object->javaGenerateEqualsAndHash) && ($filter === null || isset($filter['javaGenerateEqualsAndHash']))) {
			$output .= "\xa0\x01";
			$output .= Binary::encodeVarint((int)$object->javaGenerateEqualsAndHash);
		}

		if (isset($object->javaStringCheckUtf8) && ($filter === null || isset($filter['javaStringCheckUtf8']))) {
			$output .= "\xd8\x01";
			$output .= Binary::encodeVarint((int)$object->javaStringCheckUtf8);
		}

		if (isset($object->optimizeFor) && ($filter === null || isset($filter['optimizeFor']))) {
			$output .= "\x48";
			$output .= Binary::encodeVarint($object->optimizeFor);
		}

		if (isset($object->goPackage) && ($filter === null || isset($filter['goPackage']))) {
			$output .= "\x5a";
			$output .= Binary::encodeVarint(strlen($object->goPackage));
			$output .= $object->goPackage;
		}

		if (isset($object->ccGenericServices) && ($filter === null || isset($filter['ccGenericServices']))) {
			$output .= "\x80\x01";
			$output .= Binary::encodeVarint((int)$object->ccGenericServices);
		}

		if (isset($object->javaGenericServices) && ($filter === null || isset($filter['javaGenericServices']))) {
			$output .= "\x88\x01";
			$output .= Binary::encodeVarint((int)$object->javaGenericServices);
		}

		if (isset($object->pyGenericServices) && ($filter === null || isset($filter['pyGenericServices']))) {
			$output .= "\x90\x01";
			$output .= Binary::encodeVarint((int)$object->pyGenericServices);
		}

		if (isset($object->deprecated) && ($filter === null || isset($filter['deprecated']))) {
			$output .= "\xb8\x01";
			$output .= Binary::encodeVarint((int)$object->deprecated);
		}

		if (isset($object->ccEnableArenas) && ($filter === null || isset($filter['ccEnableArenas']))) {
			$output .= "\xf8\x01";
			$output .= Binary::encodeVarint((int)$object->ccEnableArenas);
		}

		if (isset($object->objcClassPrefix) && ($filter === null || isset($filter['objcClassPrefix']))) {
			$output .= "\xa2\x02";
			$output .= Binary::encodeVarint(strlen($object->objcClassPrefix));
			$output .= $object->objcClassPrefix;
		}

		if (isset($object->csharpNamespace) && ($filter === null || isset($filter['csharpNamespace']))) {
			$output .= "\xaa\x02";
			$output .= Binary::encodeVarint(strlen($object->csharpNamespace));
			$output .= $object->csharpNamespace;
		}

		if (isset($object->javananoUseDeprecatedPackage) && ($filter === null || isset($filter['javananoUseDeprecatedPackage']))) {
			$output .= "\xb0\x02";
			$output .= Binary::encodeVarint((int)$object->javananoUseDeprecatedPackage);
		}

		if (isset($object->uninterpretedOption) && ($filter === null || isset($filter['uninterpretedOption']))) {
			foreach ($object->uninterpretedOption instanceof \Traversable ? $object->uninterpretedOption : (array)$object->uninterpretedOption as $k => $v) {
				$output .= "\xba\x3e";
				$buffer = UninterpretedOptionMeta::toProtobuf($v, $filter === null ? null : $filter['uninterpretedOption']);
				$output .= Binary::encodeVarint(strlen($buffer));
				$output .= $buffer;
			}
		}

		return $output;
	}
349681
public function output($filename, $content)
    {
        if (!class_exists('JShrink\Minifier')) {
            throw new \Exception(sprintf('Cannot not load filter class "%s".', 'JShrink\Minifier'));
        }
        return Minifier::minify($content, array('flaggedComments' => $this->_settings['flaggedComments']));
    }
649293
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $col = new \Expose\FilterCollection();
        $col->load();
        $filters = $col->getFilterData();

        $id = $input->getOption('id');
        if ($id !== false) {
            $idList = explode(',', $id);
            foreach ($idList as $id) {
                if (array_key_exists($id, $filters)) {
                    $detail = "[".$id."] ".$filters[$id]->getDescription()."\n";
                    $detail .= "\tRule: ".$filters[$id]->getRule()."\n";
                    $detail .= "\tTags: ".implode(', ', $filters[$id]->getTags())."\n";
                    $detail .= "\tImpact: ".$filters[$id]->getImpact()."\n";

                    $output->writeLn($detail);
                } else {
                    $output->writeLn('Filter ID '.$id.' not found!');
                }
            }
            return;
        }

        foreach ($filters as $filter) {
            echo $filter->getId().': '. $filter->getDescription()."\n";
        }
        return;
    }
739175
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->validateCommand($input);

        $output->writeln('> Loading configuration file');
        $config = $input->getOption('config');
        $files = (new ConfigResolver())->getFileList($config);
        $output->writeLn('- Found '.count($files).' files');

        $preloader = (new Factory())->create($this->getOptions($input));

        $outputFile = $input->getOption('output');
        $handle = $preloader->prepareOutput($outputFile, $input->getOption('strict_types'));

        $output->writeln('> Compiling classes');

        $count = 0;
        $countSkipped = 0;
        $comments = !$input->getOption('strip_comments');

        foreach ($files as $file) {
            $count++;

            try {
                $code = $preloader->getCode($file, $comments);
                $output->writeln('- Writing '.$file);
                fwrite($handle, $code."\n");
            } catch (VisitorExceptionInterface $e) {
                $countSkipped++;
                $output->writeln('- Skipping '.$file);
            }
        }

        fclose($handle);

        $output->writeln("> Compiled loader written to $outputFile");
        $output->writeln('- Files: '.($count - $countSkipped).'/'.$count.' (skipped: '.$countSkipped.')');
        $output->writeln('- Filesize: '.(round(filesize($outputFile) / 1024)).' kb');
    }
714968
private function buildInputFilterFromForm(InputFilterInterface $inputFilter) : void
    {
        /** @var DOMElement $node */
        foreach ($this->getNodeList() as $name => $node) {
            if ($inputFilter->has($name)) {
                continue;
            }

            // Detect element type
            $type = $node->getAttribute('type');
            if ($node->tagName === 'textarea') {
                $type = 'textarea';
            } elseif ($node->tagName === 'select') {
                $type = 'select';
            }

            // Add validation
            if (array_key_exists($type, $this->formElements)) {
                $elementClass = $this->formElements[$type];
            } else {
                // Create a default validator
                $elementClass = $this->formElements['text'];
            }

            /** @var InputProviderInterface $element */
            $element = new $elementClass($node, $this->document);
            $input   = $this->factory->createInput($element);
            $inputFilter->add($input, $name);
        }
    }