Skip to content

Commit 16de5ac

Browse files
committed
Support PSR-17 StreamFactoryInterface
1 parent 7dcd804 commit 16de5ac

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/CachePlugin.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Psr\Cache\CacheItemPoolInterface;
1414
use Psr\Http\Message\RequestInterface;
1515
use Psr\Http\Message\ResponseInterface;
16+
use Psr\Http\Message\StreamFactoryInterface;
1617
use Symfony\Component\OptionsResolver\Options;
1718
use Symfony\Component\OptionsResolver\OptionsResolver;
1819

@@ -31,7 +32,7 @@ final class CachePlugin implements Plugin
3132
private $pool;
3233

3334
/**
34-
* @var StreamFactory
35+
* @var StreamFactory|StreamFactoryInterface
3536
*/
3637
private $streamFactory;
3738

@@ -48,9 +49,9 @@ final class CachePlugin implements Plugin
4849
private $noCacheFlags = ['no-cache', 'private', 'no-store'];
4950

5051
/**
51-
* @param CacheItemPoolInterface $pool
52-
* @param StreamFactory $streamFactory
53-
* @param array $config {
52+
* @param CacheItemPoolInterface $pool
53+
* @param StreamFactory|StreamFactoryInterface $streamFactory
54+
* @param array $config {
5455
*
5556
* @var bool $respect_cache_headers Whether to look at the cache directives or ignore them
5657
* @var int $default_ttl (seconds) If we do not respect cache headers or can't calculate a good ttl, use this
@@ -66,8 +67,12 @@ final class CachePlugin implements Plugin
6667
* Defaults to an empty array
6768
* }
6869
*/
69-
public function __construct(CacheItemPoolInterface $pool, StreamFactory $streamFactory, array $config = [])
70+
public function __construct(CacheItemPoolInterface $pool, $streamFactory, array $config = [])
7071
{
72+
if (!($streamFactory instanceof StreamFactory) && !($streamFactory instanceof StreamFactoryInterface)) {
73+
throw new \LogicException(\sprintf('StreamFactory must be an instance of %s or %s', StreamFactory::class, StreamFactoryInterface::class));
74+
}
75+
7176
$this->pool = $pool;
7277
$this->streamFactory = $streamFactory;
7378

@@ -91,13 +96,13 @@ public function __construct(CacheItemPoolInterface $pool, StreamFactory $streamF
9196
* This method will setup the cachePlugin in client cache mode. When using the client cache mode the plugin will
9297
* cache responses with `private` cache directive.
9398
*
94-
* @param CacheItemPoolInterface $pool
95-
* @param StreamFactory $streamFactory
96-
* @param array $config For all possible config options see the constructor docs
99+
* @param CacheItemPoolInterface $pool
100+
* @param StreamFactory|StreamFactoryInterface $streamFactory
101+
* @param array $config For all possible config options see the constructor docs
97102
*
98103
* @return CachePlugin
99104
*/
100-
public static function clientCache(CacheItemPoolInterface $pool, StreamFactory $streamFactory, array $config = [])
105+
public static function clientCache(CacheItemPoolInterface $pool, $streamFactory, array $config = [])
101106
{
102107
// Allow caching of private requests
103108
if (isset($config['respect_response_cache_directives'])) {
@@ -115,13 +120,13 @@ public static function clientCache(CacheItemPoolInterface $pool, StreamFactory $
115120
* This method will setup the cachePlugin in server cache mode. This is the default caching behavior it refuses to
116121
* cache responses with the `private`or `no-cache` directives.
117122
*
118-
* @param CacheItemPoolInterface $pool
119-
* @param StreamFactory $streamFactory
120-
* @param array $config For all possible config options see the constructor docs
123+
* @param CacheItemPoolInterface $pool
124+
* @param StreamFactory|StreamFactoryInterface $streamFactory
125+
* @param array $config For all possible config options see the constructor docs
121126
*
122127
* @return CachePlugin
123128
*/
124-
public static function serverCache(CacheItemPoolInterface $pool, StreamFactory $streamFactory, array $config = [])
129+
public static function serverCache(CacheItemPoolInterface $pool, $streamFactory, array $config = [])
125130
{
126131
return new self($pool, $streamFactory, $config);
127132
}

0 commit comments

Comments
 (0)