bit3/contao-console

此包已被弃用且不再维护。作者建议使用 contao-community-alliance/console 包。

Contao开源CMS的CLI控制台

安装: 428

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

类型:contao-module

dev-master / 1.0.x-dev 2013-10-15 15:50 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:25:44 UTC


README

在您的 config.php 中,将控制台命令类注册到 $GLOBALS['CONSOLE_CMD']

config.php

<?php

$GLOBALS['CONSOLE_CMD'][] = 'Acme\Command\GreetCommand';

GreetCommand.php

<?php

namespace = Acme\Command;

class GreetCommand extends \Symfony\Component\Console\Command\Command
{
	protected function configure()
	{
		$this
			->setName('demo:greet')
			->setDescription('Greet someone')
			->addArgument(
				'name',
				InputArgument::OPTIONAL,
				'Who do you want to greet?'
			)
			->addOption(
				'yell',
				null,
				InputOption::VALUE_NONE,
				'If set, the task will yell in uppercase letters'
			)
		;
	}

	protected function execute(InputInterface $input, OutputInterface $output)
	{
		$name = $input->getArgument('name');
		if ($name) {
			$text = 'Hello '.$name;
		} else {
			$text = 'Hello';
		}

		if ($input->getOption('yell')) {
			$text = strtoupper($text);
		}

		$output->writeln($text);
	}
}

如果您需要更复杂的设置程序,请使用 initializeConsole 钩子。

config.php

<?php

$GLOBALS['TL_HOOKS']['initializeConsole'][] = array('Acme\Console', 'myInitializeConsole');

Console.php

<?php

namespace Acme;

use Symfony\Component\Console\Application;
use Acme\Command\GreetCommand;

class Console
{
	public function myInitializeConsole(Application $application)
	{
		$application->add(new GreetCommand());
	}
}

有关详细信息,请参阅 https://symfony.ac.cn/doc/2.3/components/console/introduction.html