1

これは の定義 (の一部) でありBaseOperation、1 つの必須パラメーター ( 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
            }
        }
    }
}

Parameteror内にメソッドが見つかりませんAbstractCommand

編集: HTTP 動詞との混乱を避けるために、param 名を「method」から「foo」に変更しました。

4

2 に答える 2

0

次のようなことができます。

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

新しい 'foo' 値をプラグインに挿入している限り、目的を達成できるはずです。

于 2014-02-26T21:56:01.157 に答える