Created
January 9, 2014 14:19
-
-
Save dcsg/8334789 to your computer and use it in GitHub Desktop.
Code examples for my blog about the new feature for Symfony Console Component - set a default command
This file contains hidden or 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
<?php | |
use Acme\Command\HelloWorldCommand; | |
use Symfony\Component\Console\Application; | |
$command = new HelloWorldCommand(); | |
$application = new Application(); | |
$application->add($command); | |
$application->setDefaultCommand($command->getName()); | |
$application->run(); |
This file contains hidden or 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
namespace Acme\Command; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class HelloWorldCommand extends Command | |
{ | |
protected function configure() | |
{ | |
$this->setName('hello:world') | |
->setDescription('Outputs \'Hello World\''); | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$output->writeln('Hello World'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment