13
13
use Psr \Cache \CacheItemPoolInterface ;
14
14
use Psr \Http \Message \RequestInterface ;
15
15
use Psr \Http \Message \ResponseInterface ;
16
+ use Psr \Http \Message \StreamFactoryInterface ;
16
17
use Symfony \Component \OptionsResolver \Options ;
17
18
use Symfony \Component \OptionsResolver \OptionsResolver ;
18
19
@@ -31,7 +32,7 @@ final class CachePlugin implements Plugin
31
32
private $ pool ;
32
33
33
34
/**
34
- * @var StreamFactory
35
+ * @var StreamFactory|StreamFactoryInterface
35
36
*/
36
37
private $ streamFactory ;
37
38
@@ -48,9 +49,9 @@ final class CachePlugin implements Plugin
48
49
private $ noCacheFlags = ['no-cache ' , 'private ' , 'no-store ' ];
49
50
50
51
/**
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 {
54
55
*
55
56
* @var bool $respect_cache_headers Whether to look at the cache directives or ignore them
56
57
* @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
66
67
* Defaults to an empty array
67
68
* }
68
69
*/
69
- public function __construct (CacheItemPoolInterface $ pool , StreamFactory $ streamFactory , array $ config = [])
70
+ public function __construct (CacheItemPoolInterface $ pool , $ streamFactory , array $ config = [])
70
71
{
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
+
71
76
$ this ->pool = $ pool ;
72
77
$ this ->streamFactory = $ streamFactory ;
73
78
@@ -91,13 +96,13 @@ public function __construct(CacheItemPoolInterface $pool, StreamFactory $streamF
91
96
* This method will setup the cachePlugin in client cache mode. When using the client cache mode the plugin will
92
97
* cache responses with `private` cache directive.
93
98
*
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
97
102
*
98
103
* @return CachePlugin
99
104
*/
100
- public static function clientCache (CacheItemPoolInterface $ pool , StreamFactory $ streamFactory , array $ config = [])
105
+ public static function clientCache (CacheItemPoolInterface $ pool , $ streamFactory , array $ config = [])
101
106
{
102
107
// Allow caching of private requests
103
108
if (isset ($ config ['respect_response_cache_directives ' ])) {
@@ -115,13 +120,13 @@ public static function clientCache(CacheItemPoolInterface $pool, StreamFactory $
115
120
* This method will setup the cachePlugin in server cache mode. This is the default caching behavior it refuses to
116
121
* cache responses with the `private`or `no-cache` directives.
117
122
*
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
121
126
*
122
127
* @return CachePlugin
123
128
*/
124
- public static function serverCache (CacheItemPoolInterface $ pool , StreamFactory $ streamFactory , array $ config = [])
129
+ public static function serverCache (CacheItemPoolInterface $ pool , $ streamFactory , array $ config = [])
125
130
{
126
131
return new self ($ pool , $ streamFactory , $ config );
127
132
}
0 commit comments