Created
March 25, 2015 20:49
-
-
Save Ziiweb/5383fdcb3e87d93ec773 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
// application.php | |
require __DIR__.'/vendor/autoload.php'; | |
use Project\Console\Command\GreetCommand; | |
use Symfony\Component\Console\Application; | |
$application = new Application(); | |
$application->add(new GreetCommand); | |
$application->run(); | |
///////////////////////////////////////// | |
<?php | |
namespace Project\Console\Command; | |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class GreetCommand extends ContainerAwareCommand | |
{ | |
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); | |
} | |
$this->getContainer()->get('mailer'); //<<<<<<<<<<<<<<<<<<< trying to get the container | |
$output->writeln($text); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment