symfony2コンソールコマンドアプリがあります。コマンド(extending \Symfony\Component\Console\Command\Command
)内で、別のコマンドを呼び出します。
$this->getApplication()->run(new StringInput('cache:flush'), new NullOutput());
これは、最近のSymfonyバージョンにアップデートするまでは正常に機能していました。
しかし今、私は次のSymfony関数で例外をヒットしました(\Symfony\Component\Console\Input\ArgvInput::parseArgument()
)
private function parseArgument($token)
{
$c = count($this->arguments); ## $c is 0 !
// if input is expecting another argument, add it
if ($this->definition->hasArgument($c)) {
$arg = $this->definition->getArgument($c);
$this->arguments[$arg->getName()] = $arg->isArray()? array($token) : $token;
// if last argument isArray(), append token to last argument
} elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
$arg = $this->definition->getArgument($c - 1);
$this->arguments[$arg->getName()][] = $token;
// unexpected argument
} else {
throw new \RuntimeException('Too many arguments.'); ### this exception is thrown
}
}
両方のコマンド(元のコマンドdev:setup:run
と私たちが呼び出すコマンドcache:flush
)はパラメーターを必要としません。