Symfony进程组件-设置命令的输入参数


Symfony Process Component - Set Input Argument for command

我需要异步运行一个命令。要做到这一点,我尝试使用进程组件。

我正在尝试启动的命令正在调用一个需要一些参数的函数。这些参数由启动进程的控制器给出。

问题是我不知道如何通过Process Component传递参数给我的命令。

命令:

protected function configure()
{
    $this
        ->setName('generationpdf:classement')
        ->setDescription('Génère le PDF d''un classement.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
    ini_set('memory_limit','4000M');
    $pdf = $this->imprimerAction();
    $this->sendClassement($pdf);
    $output->writeln('PDF envoyé.');
}

控制器:

        $command = new PDFClassementCommand();
        $input = new ArrayInput(array('id' => $id, 'errata' => $errata, 'precision' => $precision, 'group' => $group, 'logoAnnee' => $logoAnnee));
        $output = new NullOutput();
        $process = new Process($command);
        $process->disableOutput();
        $process->start();

我需要使用的参数是在ArrayInput,但进程不接受数组参数

进程期望第一个参数为string。

的例子:

$process = new Process('ls');

要运行命令,您需要执行symfony console命令

$process = new Process('/var/www/my-project/bin/console generationpdf:classement')

你不必硬编码路径,参见how-to-get-the-root-dir。

您可以正常传递参数,例如从cli

运行命令
$process = new Process('/var/www/my-project/bin/console generationpdf:classement --id=5 --errata=someValue')