/** * @param PreExecuteRequest $event */ public function preExecuteRequest(PreExecuteRequest $event) { $endpoint = $event->getEndpoint(); $uri = $event->getRequest()->getUri(); $path = sprintf('%s://%s:%s%s/%s', $endpoint->getScheme(), $endpoint->getHost(), $endpoint->getPort(), $endpoint->getPath(), urldecode($uri)); $this->logger->startRequest($path); }
public function logPreExecute(PreExecuteRequest $event) { foreach ($this->requests as &$request) { if ($request['request'] === $event->getRequest()) { $request['requestStart'] = microtime(TRUE); break; } } }
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; }
public function preExecuteRequest(SolariumPreExecuteRequestEvent $event) { if (isset($this->currentRequest)) { $this->failCurrentRequest(); } if (null !== $this->stopwatch) { $this->stopwatch->start('solr', 'solr'); } $this->currentRequest = $event->getRequest(); $this->currentEndpoint = $event->getEndpoint(); if (null !== $this->logger) { $this->logger->debug($event->getEndpoint()->getBaseUri() . $this->currentRequest->getUri()); } $this->currentStartTime = microtime(true); }
public function preExecuteRequest(SolariumPreExecuteRequestEvent $event) { if (isset($this->currentRequest)) { // mop: hmmm not sure what happens when an exception is thrown :S lets be restrictive for the moment throw new \RuntimeException('Request already set'); } if (null !== $this->stopwatch) { $this->stopwatch->start('solr', 'solr'); } $this->currentRequest = $event->getRequest(); if (null !== $this->logger) { $this->logger->debug($event->getEndpoint()->getBaseUri() . $this->currentRequest->getUri()); } $this->currentStartTime = microtime(true); }
public function testExecuteRequestWithOverridingPlugin() { $request = new Request(); $response = new Response('', array('HTTP 1.0 200 OK')); $endpoint = $this->client->createEndpoint('s1'); $expectedEvent = new PreExecuteRequestEvent($request, $endpoint); $expectedEvent->setDispatcher($this->client->getEventDispatcher()); $expectedEvent->setName(Events::PRE_EXECUTE_REQUEST); $test = $this; $this->client->getEventDispatcher()->addListener(Events::PRE_EXECUTE_REQUEST, function (PreExecuteRequestEvent $event) use($test, $response, $expectedEvent) { $test->assertEquals($expectedEvent, $event); $event->setResponse($response); }); $returnedResponse = $this->client->executeRequest($request, $endpoint); $this->assertEquals($response, $returnedResponse); }
/** * @param PreExecuteRequest $event */ public function preExecuteRequest(PreExecuteRequest $event) { $this->logger->info(sprintf('run request: %s', urldecode($event->getRequest()->getUri()))); }
public function preExecuteRequest(PreExecuteRequest $event) { $this->currentRequest = $event->getRequest(); $this->currentEndpoint = $event->getEndpoint(); $this->currentStartTime = TimeUtil::getCurrentTime(); }
/** * 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()); }