symfony/控制台组件的可变数量的选项 [英] Variable number of options for symfony/console component
问题描述
如何配置 symfony/console
以接受动态选项列表?
How would one configure symfony/console
to accept a dynamic list of options?
也就是说 - 在开发步骤中不知道选项的名称,因此我需要一个应用程序来接受所有内容并使用标准 $input->getOption
公开它.
That said - the names for the options aren't known on development step so I need an application to accept everything and expose it using the standard $input->getOption
.
有没有可能轻松完成(无需在数百万个地方对组件进行黑客攻击)?
Any chance it can be done easily (without hacking the component in million places)?
我的尝试包括扩展 ArgvInput
和 InputDefinition
类,但由于各种原因(它们是客观的和 symfony/console
组件实现)失败了-具体的).简而言之:前者需要多次调用解析;后者 - 在多个地方实例化,所以我找不到合适的方法来注入它.
My attempts included extending the ArgvInput
and InputDefinition
classes but they failed due to various reasons (they are objective and symfony/console
component implementation-specific). Briefly: the former requires parsing to be invoked multiple times; the latter - is instantiated in multiple places so I just couldn't find a proper way to inject it.
推荐答案
您可以创建自己的 ArgvInput 以允许所有选项.
You can create your own ArgvInput that will allow all options.
例如,您可以在 此处
我只修改了几行:178
I have only modified lines : 178
并注释掉这些行:188-199
And comment out the lines: 188-199
然后将您的版本 ArgvInput 的实例而不是默认值传递给
Then pass instance of your version ArgvInput instead of default one to
$input = new AcceptAllArgvInput();
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
这篇关于symfony/控制台组件的可变数量的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!