Skip to content

Commit

Permalink
Update GuzzleHttpAdapter.php
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasglachant authored Jan 23, 2020
1 parent e6a1bd6 commit 4811cfe
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ClientHydra/Adapter/GuzzleHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GuzzleHttpAdapter implements HttpAdapterInterface
];
private $authorizationToken = null;

/** @var CacheItemPoolInterface */
/** @var ?CacheItemPoolInterface */
private $persistantCache;

/**
Expand All @@ -45,9 +45,6 @@ public function __construct(string $baseUrl, CacheItemPoolInterface $persistantC
$this->debugEnabled = $debugEnabled;
$this->debugData = [];
$this->executionCache = new ArrayAdapter();
if (null === $persistantCache) {
$persistantCache = new ArrayAdapter();
}
$this->persistantCache = $persistantCache;
}

Expand Down Expand Up @@ -165,7 +162,7 @@ public function call(Request $request, bool $useExecutionCache = true): Response
$requestData['cacheOrigin'] = 'execution';
}
$arrayResponse = $this->executionCache->getItem($requestHash)->get();
} elseif ($useExecutionCache && $this->persistantCache->hasItem($requestHash)) {
} elseif ($useExecutionCache && null !== $this->persistantCache && $this->persistantCache->hasItem($requestHash)) {
if ($this->debugEnabled) {
$requestData['cacheOrigin'] = 'persistant';
}
Expand All @@ -178,7 +175,7 @@ public function call(Request $request, bool $useExecutionCache = true): Response
$requestData['cache']['savedIn'][] = 'execution';
} else {
try {
$rUri = '/' === \substr($request->getUri(), 0, 1) ? \substr($request->getUri(), 1) : $request->getUri();
$rUri = substr($request->getUri(), 0, 1) === '/' ? substr($request->getUri(), 1) : $request->getUri();
/** @var Response $response */
$response = $this->client->send(
new \GuzzleHttp\Psr7\Request($request->getMethod(), $rUri, $request->getHeaders(), $request->getBody())
Expand All @@ -197,7 +194,7 @@ public function call(Request $request, bool $useExecutionCache = true): Response
}
$requestData['cacheSavedIn'][] = 'execution';

if ($request->isPersistantCacheEnable()) {
if (null !== $this->persistantCache && $request->isPersistantCacheEnable()) {
$cacheItem = $this->persistantCache->getItem($requestHash);
$cacheItem->set($arrayResponse);
$cacheItem->expiresAfter($request->getPersistantCacheTTL());
Expand Down Expand Up @@ -264,4 +261,9 @@ public function call(Request $request, bool $useExecutionCache = true): Response

return $response;
}

public function getPersistantCache(): ?CacheItemPoolInterface
{
return $this->persistantCache;
}
}

0 comments on commit 4811cfe

Please sign in to comment.