Изменение значений параметров команд Guzzle во время выполнения через плагины?

Это (часть) определения BaseOperation с одним обязательным параметром ( foo ):

 'BaseOperation' => array( 'class' => 'My\Command\MyCustomCommand', 'httpMethod' => 'POST', 'parameters' => array( 'foo' => array( 'required' => true, 'location' => 'query' ) ) ) 

Внутри плагина ChangeMethodPlugin Мне нужно изменить значение foo во время выполнения:

 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 .

EDIT : имя параметра изменено на «foo» из «метода», чтобы избежать путаницы с HTTP-глаголами.

Related of "Изменение значений параметров команд Guzzle во время выполнения через плагины?"

Вы можете использовать метод setHttpMethod() Операции, принадлежащий этой команде, но вместо этого вам нужно будет использовать событие command.before_prepare .

 <?php class ChangeMethodPlugin implements EventSubscriberInterface { public static function getSubscribedEvents() { return array('command.before_prepare' => 'onBeforeCommandPrepare'); } public function onBeforeCommandPrepare(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 'method' parameter $command->getOperation()->setHttpMethod('METHOD_NAME'); } } } } 

Вы можете сделать что-то вроде следующего:

$command->getRequest()->getQuery()->set('foo', 'bar');

До тех пор, пока вы добавили новое значение «foo» в плагин, вы сможете выполнить то, что вы хотите сделать.