「Php/Symfony/Symfony2/batch」の版間の差分
ナビゲーションに移動
検索に移動
ページの作成:「vi src/Acme/HelloBundle/Command/SampleCommand.php namespace Acme\HelloBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Com...」 |
|||
| 32行目: | 32行目: | ||
} | } | ||
==バッチ実行コマンド== | ==バッチ実行コマンド&結果== | ||
$ app/console hello:sample taro | $ app/console hello:sample taro | ||
Hello taro | |||
==参考== | ==参考== | ||
http://docs.symfony.gr.jp/symfony2/cookbook/console.html | http://docs.symfony.gr.jp/symfony2/cookbook/console.html | ||
2017年2月10日 (金) 06:30時点における最新版
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