Skip to content

Commit 92f6f2d

Browse files
authored
Merge pull request KnpLabs#414 from Nyholm/prepend_plugin
Make sure cache is added after pathprepend and addHost plugins
2 parents 653d4fe + c11a428 commit 92f6f2d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

lib/Github/Client.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Http\Discovery\StreamFactoryDiscovery;
1919
use Http\Discovery\UriFactoryDiscovery;
2020
use Http\Message\MessageFactory;
21-
use Http\Message\SteamFactory;
21+
use Nyholm\Psr7\Factory\StreamFactory;
2222
use Psr\Cache\CacheItemPoolInterface;
2323

2424
/**
@@ -309,7 +309,7 @@ public function setEnterpriseUrl($enterpriseUrl)
309309
}
310310

311311
/**
312-
* Add a new plugin to the chain
312+
* Add a new plugin to the end of the plugin chain.
313313
*
314314
* @param Plugin $plugin
315315
*/
@@ -341,6 +341,8 @@ public function getHttpClient()
341341
{
342342
if ($this->httpClientModified) {
343343
$this->httpClientModified = false;
344+
$this->pushBackCachePlugin();
345+
344346
$this->pluginClient = new HttpMethodsClient(
345347
new PluginClient($this->httpClient, $this->plugins),
346348
$this->messageFactory
@@ -457,4 +459,22 @@ public function getLastResponse()
457459
{
458460
return $this->responseHistory->getLastResponse();
459461
}
462+
463+
/**
464+
* Make sure to move the cache plugin to the end of the chain
465+
*/
466+
private function pushBackCachePlugin()
467+
{
468+
$cachePlugin = null;
469+
foreach ($this->plugins as $i => $plugin) {
470+
if ($plugin instanceof Plugin\CachePlugin) {
471+
$cachePlugin = $plugin;
472+
unset($this->plugins[$i]);
473+
474+
$this->plugins[] = $cachePlugin;
475+
476+
return;
477+
}
478+
}
479+
}
460480
}

0 commit comments

Comments
 (0)