PHP code example of contao-community-alliance / console

1. Go to this page and download the library: Download contao-community-alliance/console library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

contao-community-alliance / console example snippets




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



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);
	}
}



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



namespace Acme;

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

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