Php/Symfony/Symfony2/batch
ナビゲーションに移動
検索に移動
vi src/Acme/HelloBundle/Command/SampleCommand.php
namespace Acme\HelloBundle\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 SampleCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('hello:sample')
->setDescription('Sample someone')
->addArgument('name', InputArgument::OPTIONAL, 'sample name?')
->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);
}
}
バッチ実行コマンド&結果
$ app/console hello:sample taro Hello taro