初始化

@param  \Symfony\Component\Console\Input\InputInterface      $input
@param  \Symfony\Component\Console\Output\OutputInterface    $output
962488
protected function initialize(InputInterface $input, OutputInterface $output)
    {
        $styles = [
            // ---------------------------------------
            // Style    => [ Color, BgColor, Options ]
            // ---------------------------------------
            'title'     => [ 'white', null, ['bold'] ],
            'info'      => [ 'cyan' ],
            'warn'      => [ 'yellow', null, ['bold'] ],
            'erro'      => [ 'red', null, ['bold'] ],
            'success'   => [ 'green' ],
            'failure'   => [ 'yellow' ],
            'label'     => [ 'cyan', null, ['underscore'] ],
            'comment'   => [ 'white', null, ['reverse'] ],
            'highlight' => [ 'yellow' ],
        ];

        foreach ($styles as $name => $style) {
            $output->getFormatter()->setStyle(
                $name,
                Reflection::newInstance(
                    OutputFormatterStyle::class,
                    $style
                )
            );
        }

        $this->output = new OutputStyle($input, $output);
    }
294624
public function run(InputInterface $input, OutputInterface $output): int
    {
        return $this->console->run($input, $output);
    }
632971
private function setInputAndOutput(InputInterface $input, OutputInterface $output)
    {
        if (is_null($this->assistant)) {
            $this->assistant = new CommandAssistant();
            $this->assistant->setQuestionHelper($this->getQuestionHelper());
            $this->assistant->setKernel($this->getApplication()->getKernel());
        }
        $this->assistant->setOutput($output);
        $this->assistant->setInput($input);
    }
419662
public function execute(InputInterface $input, OutputInterface $output)
    {
        $argument = $input->getArgument($this->argumentName);
        $path = $this->basePath.'/'.$argument.'.php';

        if ($input->hasOption('restful') && $input->getOption('restful') == true) {
            $this->restful = true;
        } else {
            $this->restful = false;
        }

        $response = $this->runFileGeneratorCommand($path, $argument);

        if ($response === true) {
            $this->type ?: $this->type = 'Command';
            $output->writeln(ucfirst($this->type).' created successfully');

            return;
        }
        $output->writeln($response);
    }
854520
public function setOutput(OutputInterface $output)
    {
        $this->output = $output;
        $this->stdErr = $output instanceof ConsoleOutputInterface
            ? $output->getErrorOutput()
            : $output;
    }
686902
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $docs = new Parser(APP_PATH);
        $docs->parse();

        // {{
        $this->title('所有路由规则');
        // }}

        foreach ($docs as $class => $doc) {
            foreach ((array) $doc['methods'] as $method) {
                $this->writeln(
                    sprintf(
                        ' <info>-</> <success>%s</> <title>%s</> <info>-></> %s',
                        str_pad(strtoupper($method), 4),
                        str_pad($doc['route'], 30),
                        $class
                    )
                );
            }
        }

        $this->newLine();

        return 0;
    }
1240084
public function run(InputInterface $input = null, OutputInterface $output = null)
	{
		try
		{
			parent::run($input, $output);
		}
		catch (\Exception $e)
		{
			if (null === $output) {
				$output = new ConsoleOutput();
			}
			$message = array(
				$this->getLongVersion(),
				'',
				$e->getMessage(),
				''
			);
			$output->writeln($message);
		}
	}
101557
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($input->getArgument('version') === null) {
            $version = $this->manager->getVersionFromProvider();
            $output->writeln(sprintf('Provider: <comment>%s</comment>', get_class($this->manager->getActiveProvider())));

            $formatter = $this->manager->getFormatter();
            if ($formatter instanceof FormatterInterface) {
                $output->writeln(sprintf('Formatter: <comment>%s</comment>', get_class($formatter)));
            } else {
                $output->writeln(sprintf('Formatter: <comment>%s</comment>', 'None'));
            }
        } else {
            $version = Version::fromString($input->getArgument('version'));
            $output->writeln(sprintf('Provider: <comment>%s</comment>', 'Symfony command'));
            $output->writeln(sprintf('Formatter: <comment>%s</comment>', 'Not available'));
        }

        $incrementMajor = (int) $input->getOption('major');
        if ($incrementMajor > 0) {
            for ($i = 0; $i < $incrementMajor; $i++) {
                $version = $version->withMajorIncremented();
            }
        }

        $incrementMinor = (int) $input->getOption('minor');
        if ($incrementMinor > 0) {
            for ($i = 0; $i < $incrementMinor; $i++) {
                $version = $version->withMinorIncremented();
            }
        }

        $incrementPatch = (int) $input->getOption('patch');
        if ($incrementPatch > 0) {
            for ($i = 0; $i < $incrementPatch; $i++) {
                $version = $version->withPatchIncremented();
            }
        }

        $preRelease = $input->getOption('prerelease');
        if (!empty($preRelease)) {
            if (in_array(null, $preRelease)) {
                $preRelease = array();
            }

            $version = $version->withPreRelease($preRelease);
        }

        $build = $input->getOption('build');
        if (!empty($build)) {
            if (in_array(null, $build)) {
                $build = array();
            }

            $version = $version->withBuild($build);
        }

        $currentVersion = $this->manager->getVersion();
        if ((string) $currentVersion == (string) $version) {
            $version = $version->withPatchIncremented();
        }

        $output->writeln(sprintf('Current version: <info>%s</info>', $currentVersion));
        $output->writeln(sprintf('New version: <info>%s</info>', $version));
        if ($input->getOption('dry-run')) {
            $output->writeln(sprintf('<question>%s</question>', 'Dry run, skipping version bump'));
        } else {
            $this->manager->writeVersion($version);
        }
    }
608343
public function execute(InputInterface $input, OutputInterface $output)
    {
        if (empty($path = $input->getArgument('path'))) {
            $this->render($input, $output);
        } else {
            $this->test($input->getArgument('method'), $path, $input, $output);
        }

        return 0;
    }
1256620
protected function execute(InputInterface $input, OutputInterface $output): void
    {
        $output->writeln([
            '----------------',
            'Domain entity generator',
            '----------------',
            ''
        ]);

        $helper      = $this->getHelper('question');
        $questionSet = $this->createQuestionSet();
        $entityName  = $helper->ask($input, $output, $questionSet['entityName']);

        do {
            $propertyNames[] = $helper->ask($input, $output, $questionSet['propertyName']);
            $propertyTypes[] = $helper->ask($input, $output, $questionSet['propertyType']);
        } while ($helper->ask($input, $output, $questionSet['continue']));

        $properties = array_combine($propertyNames, $propertyTypes);

        $configuration   = $this->appConfiguration->getConfiguration();
        $entityNamespace = $configuration['framework']['root_namespace'] . 'Domain\Entity';

        $entityData = [
            'namespace'  => $entityNamespace,
            'class'      => $entityName,
            'properties' => $properties
        ];

        (new EntityGenerator($entityData))->generate();

        $output->writeln('Entity generated successfully!');
    }
1250158
public function cacheClear(InputInterface $input, OutputInterface $output)
    {
        $output->writeln(sprintf('Cache path: <info>%s</info>', __DIR__ . '/.cache'));
        $files = glob(__DIR__ . '/.cache/tables' . '/*');
        if (!empty($files)) {
            foreach ($files as $file) {
                $output->writeln('  <info>-></info> ' . $file);
                if ($input->hasParameterOption(['--clear'])) {
                    unlink($file);
                    $output->writeln(sprintf(
                        '    <info>✔</info> Table <info>"%s"</info> cache is clean <info>done.</info>',
                        pathinfo($file, PATHINFO_FILENAME)
                    ));
                }
            }
        } else {
            $output->writeln(sprintf('  <comment>!!</comment> Empty cache.'));
        }

        $files = glob(__DIR__ . '/.cache/dataset' . '/*');
        if (!empty($files)) {
            foreach ($files as $file) {
                $output->writeln('  <info>-></info> ' . $file);
                if ($input->hasParameterOption(['--clear'])) {
                    unlink($file);
                    $output->writeln(sprintf(
                        '    <info>✔</info> Table <info>"%s"</info> dataset is clean <info>done.</info>',
                        pathinfo($file, PATHINFO_FILENAME)
                    ));
                }
            }
        } else {
            $output->writeln(sprintf('  <comment>!!</comment> Empty dataset.'));
        }
    }
925161
protected function execute(InputInterface $input, OutputInterface $output)
    {
        // 读取所有服务
        $servers = array_keys(Config::get('server', []));
        // 当前服务
        $server = $input->getArgument('server');

        if ($server !== null && ! isset($servers[$server])) {
            $this->error('启动失败, 未定义 [' . $server . '] 服务');
            return 0;
        } elseif ($server === null && $servers === []) {
            $this->error('启动失败, 未定义任何服务');
            return 0;
        }

        // {{
        $this->title('启动服务进程');
        // }}

        if ($server !== null) {
            $servers = (array) $server;
        }

        unset($server);

        $runner = new Runner($output);

        try {
            foreach ($servers as $server) {
                if ($runner->isRunning($server)) {
                    $this->fail('<label>' . $server . '</> 处于运行中');
                } else {
                    $ret = $runner->runCommand('start', $server);

                    $this->result(
                        '启动 <label>' . $server . '</> 服务进程',
                        $ret['code'] === 0
                    );
                }

                $this->wait();
            }
        } catch (\Exception $e) {
            $this->fail($e->getMessage());
        }

        $this->newLine();

        return 0;
    }
391077
protected function execute(InputInterface $input, OutputInterface $output)
    {
		$this->input = $input;
		$this->output = $output;
		$this->force = $input->getOption('force');
		
		$helper = $this->getHelper('question');
		
        $userQuestion = new Question('User (root): ', 'root');
		
        $passwordQuestion = new Question('Password (): ', '');
		$passwordQuestion->setHidden(true);
		$passwordQuestion->setHiddenFallback(false);

        $hostQuestion = new Question('Host (localhost): ', 'localhost');
        $driverQuestion = new Question('Driver (pdo_mysql): ', 'pdo_mysql');
		
		$user = $helper->ask($input, $output, $userQuestion);
		$password = $helper->ask($input, $output, $passwordQuestion);
		$host = $helper->ask($input, $output, $hostQuestion);
		$driver = $helper->ask($input, $output, $driverQuestion);
		
		$connectionParams = array(
			'user' => $user,
			'password' => $password,
			'host' => $host,
			'driver' => $driver
		);
		
		try {
			$conn = $this->createConnection($connectionParams);
			
			$sm = $conn->getSchemaManager();
			
			$databases = $sm->listDatabases();
			
			$question = new ChoiceQuestion(
				'Database',
				$databases,
				0
			);
			$question->setErrorMessage('Selected database is not valid');

			$dbName = $helper->ask($input, $output, $question);
			$output->writeln('Chosen database: ' . $dbName);
			
			//Add the dbname property
			$connectionParams['dbname'] = $dbName;
			
			$conn = $this->createConnection($connectionParams);
			
			$sm = $conn->getSchemaManager();
		
			$tables = $sm->listTables();
			
			$this->loadConfiguration();
			
			$progress = new ProgressBar($output, count($tables));
			$progress->start();
			
			foreach ($tables as $table) {
				//$output->writeln($table->getName() . " columns:\n\n");
					
				//Columns
				/*
				foreach ($table->getColumns() as $column) {
					//$output->writeln(' - ' . $column->getName() . ': ' . $column->getType() . "\n");
				}
				*/
					
				//Foreign keys
				$name = $table->getName();
				$table = $sm->listTableDetails($name);
				//$foreignKeys = $table->getForeignKeys();
				//$output->writeln("Foreign keys (" . count($foreignKeys) . ")");
				/*
				foreach ($foreignKeys as $foreignKey) {
					//$output->writeln("\n");
					$foreignColumns = $foreignKey->getForeignColumns();
					$localColumns = $foreignKey->getLocalColumns();
					foreach($foreignColumns as $key => $foreignColumn){
						//$output->writeln($foreignKey->getLocalTableName() . "." . $localColumns[$key] . " <=> " . $foreignKey->getForeignTableName() . "." . $foreignColumn . "\n");
					}
				}
				*/
		
				$primaryKeys = $table->getPrimaryKeyColumns();
				//$output->writeln("Primary keys (" . count($primaryKeys) . ")");
				/*
				foreach ($primaryKeys as $primaryKey) {
					//$output->writeln("\n" . $primaryKey);
				}
				*/
				
				//$output->writeln("\n\n");
				$this->generateCode($name, reset($primaryKeys));
				
				$progress->advance();
			}
			
			$progress->finish();
		} catch(\Exception $ex){
			$output->writeln('Generator has found the current exception: ');
			$output->writeln($ex->getMessage());
		}
    }
828092
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->addOption('--environment', '-e', InputArgument::OPTIONAL);
        $input->setOption('environment', getenv('RAD_ENVIRONMENT'));
        parent::execute($input, $output);
    }
462491
public function execute(InputInterface $input, OutputInterface $output)
    {
        $inOut     = $this->wrapIo($input, $output);
        $container = $this->createContainer($this->getComposer(), static::NAME);

        $argAction = static::ARG_ACTION;
        $action    = $inOut->getArgument($argAction);
        switch ($action) {
            case static::ACTION_CONNECT:
                $this->executeConnect($container, $inOut);
                break;
            case static::ACTION_CREATE:
                $this->executeCreate($container, $inOut);
                break;
            default:
                $inOut->writeError("Unknown value `$action` for argument `$argAction`." . PHP_EOL);
                break;
        }
    }
1326465
protected function execute(InputInterface $input, OutputInterface $output)
    {
        try {
            $port   = $this->config['port'] ?: 9001;
            $public = $this->config['public'] ?: 'Public';

            $output->writeln([
                '<bg=red;>=================================</>',
                '请在浏览器里预览网站效果',
                '地址：http://localhost:'.$port,
                '<bg=red;>=================================</>'
            ]);
            // open explorer
            if ( $this->config['auto_open'] ) {
                if (strstr(PHP_OS, 'WIN')) {
                    $win_cmd = "cd ".ROOT." && ". 'explorer http://localhost:'.$port;
                    system($win_cmd);
                }else{
                    $mac_cmd = "cd ".ROOT." && ". 'open http://localhost:'.$port;
                    system($mac_cmd);
                }
            }
            // 为了减少复杂度，直接使用php自带的调试服务器
            $cmd = "cd ".ROOT." && ". 'php -S ' . 'localhost:'.$port . ' -t ' . $public;
            system($cmd);
        } catch (Exception $e) {
            $output->writeln('<bg=red;>Start Server Error</>');
        }
    }
284393
public function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var QuestionHelper $helper */
        $helper = $this->getHelper('question');

        $copyrightYear = date('Y');
        $packageName = 'Unknown';
        $packageOwner = 'Contributors';
        $packageOwnerEmail = '';

        if ($input->hasOption('name')) {
            $packageName = $input->getOption('name');
        } else {
            $packageName = $helper->ask($input, $output, new Question(
                'What is the package name? '
            ));
        }

        if ($input->hasOption('owner')) {
            $packageOwner = $input->getOption('owner');
        } else {
            $packageOwner = $helper->ask($input, $output, new Question(
                'Who is the package owner? '
            ));
        }

        if ($input->hasOption('email')) {
            $packageOwnerEmail = $input->getOption('email');
        } else {
            $packageOwnerEmail = $helper->ask($input, $output, new Question(
                'What is the contact email of the owner? (Optional) ',
                ''
            ));
        }

        $template = file_get_contents(
            __DIR__ . '/../../../../resources/project/formatter.yml'
        );

        $template = str_replace('<year>', $copyrightYear, $template);
        $template = str_replace('<owner>', $packageOwner, $template);
        $template = str_replace('<package>', $packageName, $template);
        $template = str_replace('<email>', $packageOwnerEmail, $template);

        $filesystem = new Filesystem();

        if ($filesystem->exists('.formatter.yml')) {
            if ($helper->ask($input, $output, new ConfirmationQuestion(
                '.formatter.yml already exists. Overwrite? (y/N) ',
                false
            ))) {
                $filesystem->dumpFile('.formatter.yml', $template);
                $output->writeln('Wrote .formatter.yml');
            }
        } else {
            $filesystem->dumpFile('.formatter.yml', $template);
            $output->writeln('Wrote .formatter.yml');
        }

        if (!$filesystem->exists('.editorconfig')) {
            $filesystem->dumpFile(
                '.editorconfig',
                file_get_contents(
                    __DIR__ . '/../../../../resources/project/editorconfig'
                )
            );
            $output->writeln('Wrote .editorconfig');
        }

        return 0;
    }