/** {@inheritdoc} */ public function count(RpcClientInterface $client, ApiMetadata $metadata, array $parameters) { call_user_func_array([$this, 'configure'], $parameters); $parameters = $this->getSearchRequestParams(); $request = new RpcRequest($metadata->getMethodContainer()->getMethod('count'), $parameters); return (int) $client->invoke($request)->getResponse($request)->getBody(); }
/** {@inheritdoc} */ public function invoke($calls) { $this->stopwatch->start($this->clientName, 'rpc_call'); $collection = new TraceableResponseCollection($this->client->invoke($calls), $this->stopwatch, $this->clientName); $this->stopwatch->stop($this->clientName); return $collection; }
/** {@inheritdoc} */ public function invoke($calls) { /** @var RpcRequestInterface[] $loggedCalls */ $loggedCalls = $calls; if (!is_array($loggedCalls)) { $loggedCalls = [$loggedCalls]; } foreach ($loggedCalls as $call) { $this->logger->debug(sprintf('%s Invoking RPC method "%s"', spl_object_hash($call), $call->getMethod()), json_decode(json_encode($call->getParameters()), true)); } return new LoggableResponseCollection($this->decoratedClient->invoke($calls), $this->logger); }
/** {@inheritdoc} */ public function find(RpcClientInterface $client, ApiMetadata $metadata, array $identifiers) { $request = new RpcRequest($metadata->getMethodContainer()->getMethod('find'), $identifiers); $entityCache = $this->manager->getEntityCache(); if (null !== $entityCache) { $body = $entityCache->get($metadata->getName(), $identifiers); if (null !== $body) { return $body; } } $response = $client->invoke([$request])->getResponse($request); if (!$response->isSuccessful()) { return null; } $body = $response->getBody(); if (null !== $entityCache) { $entityCache->set($body, $metadata, $identifiers); } return $body; }
/** {@inheritdoc} */ public function invoke($calls) { if (!is_array($calls)) { $calls = [$calls]; } $items = []; $proxiedRequests = []; foreach ($calls as $call) { $key = $this->extractor->getKey($call); $item = $this->cache->getItem($key); $items[$key]['request'] = $call; $items[$key]['item'] = $item; if (!$item->isHit()) { $proxiedRequests[] = $call; } } // Prevent batch calls when not necessary if (count($proxiedRequests) === 1 && !is_array($calls)) { $proxiedRequests = array_shift($proxiedRequests); } return new CacheableResponseCollection($this->cache, $this->extractor, $items, $this->decoratedClient->invoke($proxiedRequests), $this->ttl); }
private function init() { $this->collection = $this->client->invoke($this->requests); $this->requests = []; $this->initialized = true; }
/** {@inheritdoc} */ public function invoke($calls) { $this->profiler->registerCalls($calls); return new ProfiledResponseCollection($this->client->invoke($calls), $this->profiler); }