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
@@ -33,7 +34,7 @@ final class CachePlugin implements Plugin
33
34
private $ pool ;
34
35
35
36
/**
36
- * @var StreamFactory
37
+ * @var StreamFactory|StreamFactoryInterface
37
38
*/
38
39
private $ streamFactory ;
39
40
@@ -50,9 +51,9 @@ final class CachePlugin implements Plugin
50
51
private $ noCacheFlags = ['no-cache ' , 'private ' , 'no-store ' ];
51
52
52
53
/**
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 {
56
57
*
57
58
* @var bool $respect_cache_headers Whether to look at the cache directives or ignore them
58
59
* @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
69
70
* Defaults to an empty array
70
71
* }
71
72
*/
72
- public function __construct (CacheItemPoolInterface $ pool , StreamFactory $ streamFactory , array $ config = [])
73
+ public function __construct (CacheItemPoolInterface $ pool , $ streamFactory , array $ config = [])
73
74
{
75
+ if (!($ streamFactory instanceof StreamFactory) && !($ streamFactory instanceof StreamFactoryInterface)) {
76
+ throw new \TypeError (\sprintf ('StreamFactory must be an instance of %s or %s. ' , StreamFactory::class, StreamFactoryInterface::class));
77
+ }
78
+
74
79
$ this ->pool = $ pool ;
75
80
$ this ->streamFactory = $ streamFactory ;
76
81
@@ -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