public function testForceSet() { $plugin = new DataSetter(array('test_key' => 'test_value'), true); $command = new OperationCommand(); $command->set('test_key', 'already_stated_value'); $event = new Event(array('command' => $command)); $plugin->register($this->client); $this->client->getEventDispatcher()->dispatch('command.before_prepare', $event); $this->assertSame('test_value', $command->get('test_key')); }
/** * @param MeasurementProtocolClient $client */ public function register($client) { $client->getEventDispatcher()->addListener('command.before_prepare', function ($e) { /** @var \Guzzle\Service\Command\OperationCommand $command */ $command = $e['command']; if (!isset($_SERVER['HTTP_USER_AGENT'])) { return; } if ($command->hasKey(HitInterface::FIELD_USER_AGENT)) { return; } $command->set(HitInterface::FIELD_USER_AGENT, $_SERVER['HTTP_USER_AGENT']); }); }
/** * @param MeasurementProtocolClient $client */ public function register($client) { $data =& $this->data; $force =& $this->force; $client->getEventDispatcher()->addListener('command.before_prepare', function ($e) use($data, $force) { /** @var \Guzzle\Service\Command\OperationCommand $command */ $command = $e['command']; foreach ($data as $key => $val) { if (!$command->hasKey($key) || $force) { $command->set($key, $val); } } }); }
/** * @param MeasurementProtocolClient $client */ public function register($client) { $cookieName = $this->cookieName; $client->getEventDispatcher()->addListener('command.before_prepare', function ($e) use($cookieName) { if (!array_key_exists($cookieName, $_COOKIE)) { return; } $parser = new Parser(); $data = $parser->parse($_COOKIE[$cookieName]); /** @var \Guzzle\Service\Command\OperationCommand $command */ $command = $e['command']; if (!$command->hasKey(HitInterface::FIELD_CUSTOMER_ID)) { $command->set(HitInterface::FIELD_CUSTOMER_ID, $data->getClientId()); } }); }