Skip to content

Commit a4e5617

Browse files
committed
Support PSR-17 StreamFactoryInterface
1 parent 1588378 commit a4e5617

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

@@ -33,7 +34,7 @@ final class CachePlugin implements Plugin
3334
private $pool;
3435

3536
/**
36-
* @var StreamFactory
37+
* @var StreamFactory|StreamFactoryInterface
3738
*/
3839
private $streamFactory;
3940

@@ -50,9 +51,9 @@ final class CachePlugin implements Plugin
5051
private $noCacheFlags = ['no-cache', 'private', 'no-store'];
5152

5253
/**
53-
* @param CacheItemPoolInterface $pool
54-
* @param StreamFactory $streamFactory
55-
* @param array $config {
54+
* @param CacheItemPoolInterface $pool
55+
* @param StreamFactory|StreamFactoryInterface $streamFactory
56+
* @param array $config {
5657
*
5758
* @var bool $respect_cache_headers Whether to look at the cache directives or ignore them
5859
* @var int $default_ttl (seconds) If we do not respect cache headers or can't calculate a good ttl, use this
@@ -69,8 +70,12 @@ final class CachePlugin implements Plugin
6970
* Defaults to an empty array
7071
* }
7172
*/
72-
public function __construct(CacheItemPoolInterface $pool, StreamFactory $streamFactory, array $config = [])
73+
public function __construct(CacheItemPoolInterface $pool, $streamFactory, array $config = [])
7374
{
75+
if (!($streamFactory instanceof StreamFactory) && !($streamFactory instanceof StreamFactoryInterface)) {
76+
throw new \TypeError(\sprintf('Argument 2 passed to %s::__construct() must be of type %s|%s, %s given.', self::class, StreamFactory::class, StreamFactoryInterface::class, \is_object($streamFactory) ? \get_class($streamFactory) : \gettype($streamFactory)));
77+
}
78+
7479
$this->pool = $pool;
7580
$this->streamFactory = $streamFactory;
7681

@@ -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)