public function onPreExecuteRequest(PreExecuteRequestEvent $event) { if (null === $this->currentRequestCacheProfile) { return; } if (null === $this->currentRequestCacheProfile->getKey()) { $this->currentRequestCacheProfile->setKey(sha1($event->getRequest()->getUri())); } $key = $this->currentRequestCacheProfile->getKey(); if (false === ($serializedResponse = $this->getCache()->fetch($key))) { return; } if (false === ($response = unserialize($serializedResponse))) { return; } $event->setResponse($response); $event->stopPropagation(); // Make sure we do not save the $response in the cache later $this->currentRequestCacheProfile = null; }
/** * Event hook to adjust client settings just before query execution * * @param PreExecuteRequestEvent $event */ public function preExecuteRequest(PreExecuteRequestEvent $event) { $adapter = $this->client->getAdapter(); // save adapter presets (once) to allow the settings to be restored later if ($this->defaultEndpoint == null) { $this->defaultEndpoint = $this->client->getEndpoint()->getKey(); } // check querytype: is loadbalancing allowed? if (!array_key_exists($this->queryType, $this->blockedQueryTypes)) { $response = $this->getLoadbalancedResponse($event->getRequest()); } else { $endpoint = $this->client->getEndpoint($this->defaultEndpoint); $this->lastEndpoint = null; // execute request and return result $response = $adapter->execute($event->getRequest(), $endpoint); } $event->setResponse($response); }
/** * @depends testConstructorAndGetters * * @param PreExecuteRequest $event */ public function testSetAndGetQuery($event) { $response = new Response('', array('HTTP 1.0 200 OK')); $event->setResponse($response); $this->assertEquals($response, $event->getResponse()); }