Front controller for the command line interface (`app/console`). You can use doc/examples/console.phpcs as
template for `app/console`

@param InputInterface|null $input

@return int
326693
final public function console(InputInterface $input)
    {
        if (!$input) {
            $input = new ArgvInput();
        }
        $application = new Application($this);
        return $application->run($input);
    }
319055
public function run(InputInterface $input = null, OutputInterface $output = null)
    {
        $this->setAutoExit(false);
        $this->getContainer()->boot();
        $this->setDispatcher($this->getContainer()['dispatcher']);
        $this->getContainer()['dispatcher']->dispatch(ConsoleEvents::INIT, new ConsoleEvent($this));
        $this->getContainer()->flush();
        $exitCode = parent::run($input, $output);
        $this->getContainer()->terminate(new Request(), new Response());

        return $exitCode;
    }
343188
public function run($input = null)
    {
        $callback = $this->getCallback();

        ob_start();

        $exitCode = $callback($input);

        $output = ob_get_contents();

        ob_end_clean();

        // Run the piped command, if any
        if ($this->hasPipedCommand()) {
            $pipedCommand = $this->getPipedCommand();

            $pipedCommand->run($output);

            $output      = $pipedCommand->getOutput();
            $exitCode    = $pipedCommand->getExitCode();
            $errorOutput = $pipedCommand->getErrorOutput();
        }

        $this->_output = $output;
        $this->_exitCode = $exitCode;

        return $this;
    }
5462
public function parse($input)
    {
        if (strlen($input) == 0) {
            return null;
        }
        return $this->parser->parse(new TokenStream($this->tokenizer->getTokens($input)));
    }
294624
public function run(InputInterface $input, OutputInterface $output): int
    {
        return $this->console->run($input, $output);
    }
493098
public function run($input = null)
    {
        $descriptorSpec = array(
            0 => array('pipe', 'r'),
            1 => array('pipe', 'w'),
            2 => array('pipe', 'w')
        );
        $process = proc_open(
            $this->_command,
            $descriptorSpec,
            $pipes,
            null,
            $this->_env
        );
        if (is_resource($process)) {
            fwrite($pipes[0], $input);
            fclose($pipes[0]);

            $this->_output = stream_get_contents($pipes[1]);
            fclose($pipes[1]);

            $this->_error = stream_get_contents($pipes[2]);
            fclose($pipes[2]);
            proc_close($process);
        }
        return $this->_output;
    }
1281580
public function run(InputInterface $input = null, OutputInterface $output = null)
    {
        if ($input !== null) {
            $in = $input;
        } else {
            $in = $this->getInput();
        }

        return parent::run($in, $output);
    }
324753
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->startCommand($output);
        $pluginHash = $input->getArgument('hash');
        $plugin = $this
            ->pluginRepository
            ->findOneBy([
                'hash' => $pluginHash,
            ]);

        if (!($plugin instanceof Plugin)) {
            $this->printMessageFail(
                $output,
                'Plugin',
                'Plugin with hash "' . $pluginHash . '" not found'
            );

            return null;
        }

        $plugin->disable();
        $this
            ->pluginObjectManager
            ->flush($plugin);

        $this->printMessage(
            $output,
            'Plugin',
            'Plugin with hash "' . $pluginHash . '" disabled'
        );

        $this->finishCommand($output);
    }
454987
protected function execute(
        InputInterface $input,
        OutputInterface $output
    ): int {
        $this->define();

        $patterns = array_keys($this->methods);

        if ($this->shuffleQueues()) {
            shuffle($patterns);
        }

        $this
            ->redis
            ->psubscribe($patterns,
                function ($redis, $pattern, $channel, $payloadSerialized) use ($input, $output) {
                    $payload = $this->serializer->revert($payloadSerialized);
                    $method = $this->methods[$pattern];

                    /*
                     * All custom methods must have these parameters
                     *
                     * InputInterface  $input   An InputInterface instance
                     * OutputInterface $output  An OutputInterface instance
                     * Mixed           $payload Payload
                     */
                    $this->$method($input, $output, $payload);
                });

        $this->beforeDie();

        return 0;
    }
1225427
protected function execute(InputInterface $input, OutputInterface $output) : int
    {
        return !is_null($this->exitCode) ? $this->exitCode : 0;
    }
592211
public function handle($input, IResponse $response = null) : int
    {
        if ($response === null) {
            $response = new ConsoleResponse(new Compiler(new Lexer(), new Parser()));
        }

        try {
            $request = $this->requestParser->parse($input);

            if ($this->isInvokingHelpCommand($request)) {
                // We are going to execute the help command
                $compiledCommand = $this->getCompiledHelpCommand($request);
            } elseif ($this->isInvokingVersionCommand($request)) {
                // We are going to execute the version command
                $compiledCommand = new VersionCommand($this->applicationVersion);
            } elseif ($this->commandCollection->has($request->getCommandName())) {
                // We are going to execute the command that was entered
                $command = $this->commandCollection->get($request->getCommandName());
                $compiledCommand = $this->commandCompiler->compile($command, $request);
            } else {
                // We are defaulting to the about command
                $compiledCommand = new AboutCommand($this->commandCollection, new PaddingFormatter(),
                    $this->applicationVersion);
            }

            $statusCode = $compiledCommand->execute($response);

            if ($statusCode === null) {
                return StatusCodes::OK;
            }

            return $statusCode;
        } catch (InvalidArgumentException $ex) {
            $response->writeln("<error>{$ex->getMessage()}</error>");

            return StatusCodes::ERROR;
        } catch (Exception $ex) {
            $response->writeln("<fatal>{$ex->getMessage()}</fatal>");

            return StatusCodes::FATAL;
        } catch (Throwable $ex) {
            $response->writeln("<fatal>{$ex->getMessage()}</fatal>");

            return StatusCodes::FATAL;
        }
    }
1172038
public function runProcess(string $script, ?string $input = null): int
    {
        $this->out()->out();
        $this->addMessage('>>> ' . $script, 'info');

        if (class_exists(Process::class)) {
            $process = new Process([$script]);

            if ($input !== null) {
                $process->setInput($input);
            }

            return $process->run(function ($type, $buffer) {
                if (Process::ERR === $type) {
                    $this->io->err($buffer, false);
                } else {
                    $this->io->out($buffer, false);
                }
            });
        }

        system($script, $return);

        return (int) $return;
    }
370118
public function run(InputInterface $input, OutputInterface $output): int
    {
        $command = (string) $input;
        $command = strtr($command, [
            ' -name' => ' -N',
            ' -type' => ' -T',
            ' -maxdepth' => ' -M',
            ' -delete' => ' -d true',
        ]);

        return parent::run(new StringInput($command), $output);
    }
1156581
public function getArgument(InputInterface $input, $key): ?string
    {
        if ($input->hasArgument($key)) {
            return $input->getArgument($key);
        }
        if (isset($this->arguments[$key])) {
            return $this->arguments[$key];
        }

        return null;
    }
1341932
public function run(InputInterface $input = null, OutputInterface $output = null)
    {
        $this->boot();

        return $this->container['console']->run($input, $output);
    }
910022
protected function execute(InputInterface $input, OutputInterface $output): ?int
    {
        $username = $this->getUsername($input, $output);
        $user = $this->findUser($output, $username);
        if (null === $user) {
            return 1;
        }

        $password = $this->getPassword($input, $output);
        if ($password) {
            $this->userManager->setPlainTextPassword($user, $password);
        } else {
            $this->userManager->requestNewPassword($user);
        }
        $this->userManager->save($user);

        if ($password) {
            $message = $this->translator->trans(
                'user.password_changed_success',
                ['%username%' => $username],
                'security'
            );
        } else {
            $message = $this->translator->trans(
                'user.password_request_sent',
                ['%username%' => $username],
                'security'
            );
        }
        $output->writeln("<info>{$message}</info>");

        return 0;
    }
417052
protected function getLoader(Console\Input\InputInterface $input)
    {
        $inputFile = $input->getOption('input');

        if ($input->getOption('edit')) {
            if ($inputFile !== $this->getDefinition()->getOption('input')->getDefault()) {
                throw new \InvalidArgumentException("You cannot specify both --edit (-e) and --input (-i)");
            }
            $inputFile = $input->getOption('edit');
        }

        if ($inputFile === '-') {
            $inputFile = 'php://stdin';
            if (!($inputFormat = $input->getOption('input-format'))) {
                $inputFormat = 'json';
            }
        } elseif (!($inputFormat = $input->getOption('input-format'))) {
            // guess type based on extension.
            $inputFormat = Loader\Factory::guessType($inputFile);
        }

        $input->setOption('input-format', $inputFormat);

        $loader = Loader\Factory::createLoader($inputFormat);
        $inputStream = fopen($inputFile, 'r');
        if (!$inputStream) {
            throw new \RuntimeException("Could not open input");
        }

        if ($input->getOption('buffer') || $input->getOption('edit')) {
            $tmp = fopen('php://memory', 'rw');
            fwrite($tmp, stream_get_contents($inputStream));
            fseek($tmp, 0);
            $inputStream = $tmp;
        }
        $loader->setInput($inputStream);
        return $loader;
    }