通过插件在运行时更改Guzzle命令的参数值? [英] Changing parameter values of Guzzle commands at runtime, through plugins?
本文介绍了通过插件在运行时更改Guzzle命令的参数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是BaseOperation
定义的一部分,带有一个强制性参数(foo
):
This is (part of) the definition of BaseOperation
, with one mandatory parameter (foo
):
'BaseOperation' => array(
'class' => 'My\Command\MyCustomCommand',
'httpMethod' => 'POST',
'parameters' => array(
'foo' => array(
'required' => true,
'location' => 'query'
)
)
)
在ChangeMethodPlugin
插件内部,我需要在运行时修改foo
的值:
Inside ChangeMethodPlugin
plugin I need to modify the value of foo
at runtime:
class ChangeMethodPlugin implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array('command.before_send' => 'onBeforeCommandSend');
}
public function onBeforeCommandSend(Event $event)
{
/** @var \Guzzle\Service\Command\CommandInterface $command */
$command = $event['command'];
// Only if test configuration is true
if ($command->getClient()->getConfig(ClientOptions::TEST)) {
// Only if command is MyCustomCommand
if ($command instanceof MyCustomCommand) {
// Here I need to change the value of 'foo' parameter
}
}
}
}
我在中找不到任何方法Parameter
或 AbstractCommand
.
编辑:参数名称从方法"更改为"foo",以避免与HTTP动词混淆.
EDIT: param name changed to "foo" from "method" to avoid confusion with HTTP verbs.
推荐答案
您可以执行以下操作:
$command->getRequest()->getQuery()->set('foo', 'bar');
只要您将新的'foo'值注入到插件中,您就应该能够完成您想做的事情.
So long as you have injected the new 'foo' value into the plugin, you should be able to accomplish what you are looking to do.
这篇关于通过插件在运行时更改Guzzle命令的参数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文