6 php symfony-components symfony-console
我在 Symfony 控制台应用程序中定义了两个命令,clean-redis-keys并且clean-temp-files. 我想定义一个clean执行这两个命令的命令。
我该怎么做?
从另一个命令调用命令很简单:
Run Code Online (Sandbox Code Playgroud)use Symfony\Component\Console\Input\ArrayInput; // ... protected function execute(InputInterface $input, OutputInterface $output) { $command = $this->getApplication()->find('demo:greet'); $arguments = array( 'command' => 'demo:greet', 'name' => 'Fabien', '--yell' => true, ); $greetInput = new ArrayInput($arguments); $returnCode = $command->run($greetInput, $output); // ... }首先,
find()通过传递命令名称来指定要执行的命令。然后,您需要使用ArrayInput要传递给命令的参数和选项创建一个新的。最终,调用该
run()方法实际上执行了命令并返回命令的返回代码(命令execute()方法的返回值)。
| 归档时间: |
|
| 查看次数: |
6269 次 |
| 最近记录: |