6
6
7
7
use BadMethodCallException ;
8
8
use Doctrine \Common \Cache \Cache ;
9
- use Doctrine \Common \Cache \CacheProvider ;
10
9
use Doctrine \Common \Cache \Psr6 \DoctrineProvider ;
11
10
use Doctrine \ORM \Cache \CollectionCacheEntry ;
12
11
use Doctrine \ORM \Cache \Region ;
13
12
use Doctrine \ORM \Cache \Region \DefaultRegion ;
14
13
use Doctrine \Tests \Mocks \CacheEntryMock ;
15
14
use Doctrine \Tests \Mocks \CacheKeyMock ;
15
+ use Psr \Cache \CacheItemInterface ;
16
+ use Psr \Cache \CacheItemPoolInterface ;
16
17
use Symfony \Component \Cache \Adapter \ArrayAdapter ;
17
18
18
19
use function assert ;
19
- use function class_exists ;
20
20
21
21
/**
22
22
* @group DDC-2183
@@ -36,15 +36,11 @@ public function testGetters(): void
36
36
37
37
public function testSharedRegion (): void
38
38
{
39
- if (! class_exists (ArrayCache::class)) {
40
- self ::markTestSkipped ('Test only applies with doctrine/cache 1.x ' );
41
- }
42
-
43
39
$ cache = new SharedArrayCache ();
44
40
$ key = new CacheKeyMock ('key ' );
45
41
$ entry = new CacheEntryMock (['value ' => 'foo ' ]);
46
- $ region1 = new DefaultRegion ('region1 ' , $ cache ->createChild ());
47
- $ region2 = new DefaultRegion ('region2 ' , $ cache ->createChild ());
42
+ $ region1 = new DefaultRegion ('region1 ' , DoctrineProvider:: wrap ( $ cache ->createChild () ));
43
+ $ region2 = new DefaultRegion ('region2 ' , DoctrineProvider:: wrap ( $ cache ->createChild () ));
48
44
49
45
self ::assertFalse ($ region1 ->contains ($ key ));
50
46
self ::assertFalse ($ region2 ->contains ($ key ));
@@ -135,76 +131,71 @@ public function corruptedDataDoesNotLeakIntoApplicationWhenGettingMultipleEntrie
135
131
}
136
132
}
137
133
138
- if (class_exists (ArrayCache::class)) {
139
- /**
140
- * Cache provider that offers child cache items (sharing the same array)
141
- *
142
- * Declared as a different class for readability purposes and kept in this file
143
- * to keep its monstrosity contained.
144
- *
145
- * @internal
146
- */
147
- final class SharedArrayCache extends ArrayCache
134
+ /**
135
+ * Cache provider that offers child cache items (sharing the same array)
136
+ *
137
+ * Declared as a different class for readability purposes and kept in this file
138
+ * to keep its monstrosity contained.
139
+ *
140
+ * @internal
141
+ */
142
+ final class SharedArrayCache extends ArrayAdapter
143
+ {
144
+ public function createChild (): CacheItemPoolInterface
148
145
{
149
- public function createChild (): Cache
150
- {
151
- return new class ($ this ) extends CacheProvider {
152
- /** @var ArrayCache */
153
- private $ parent ;
154
-
155
- public function __construct (ArrayCache $ parent )
156
- {
157
- $ this ->parent = $ parent ;
158
- }
159
-
160
- /**
161
- * {@inheritDoc}
162
- */
163
- protected function doFetch ($ id )
164
- {
165
- return $ this ->parent ->doFetch ($ id );
166
- }
167
-
168
- /**
169
- * {@inheritDoc}
170
- */
171
- protected function doContains ($ id )
172
- {
173
- return $ this ->parent ->doContains ($ id );
174
- }
175
-
176
- /**
177
- * {@inheritDoc}
178
- */
179
- protected function doSave ($ id , $ data , $ lifeTime = 0 )
180
- {
181
- return $ this ->parent ->doSave ($ id , $ data , $ lifeTime );
182
- }
183
-
184
- /**
185
- * {@inheritDoc}
186
- */
187
- protected function doDelete ($ id )
188
- {
189
- return $ this ->parent ->doDelete ($ id );
190
- }
191
-
192
- /**
193
- * {@inheritDoc}
194
- */
195
- protected function doFlush ()
196
- {
197
- return $ this ->parent ->doFlush ();
198
- }
199
-
200
- /**
201
- * {@inheritDoc}
202
- */
203
- protected function doGetStats ()
204
- {
205
- return $ this ->parent ->doGetStats ();
206
- }
207
- };
208
- }
146
+ return new class ($ this ) implements CacheItemPoolInterface {
147
+ /** @var CacheItemPoolInterface */
148
+ private $ parent ;
149
+
150
+ public function __construct (CacheItemPoolInterface $ parent )
151
+ {
152
+ $ this ->parent = $ parent ;
153
+ }
154
+
155
+ public function getItem ($ key ): CacheItemInterface
156
+ {
157
+ return $ this ->parent ->getItem ($ key );
158
+ }
159
+
160
+ public function getItems (array $ keys = []): iterable
161
+ {
162
+ return $ this ->parent ->getItems ($ keys );
163
+ }
164
+
165
+ public function hasItem ($ key ): bool
166
+ {
167
+ return $ this ->parent ->hasItem ($ key );
168
+ }
169
+
170
+ public function clear (): bool
171
+ {
172
+ return $ this ->parent ->clear ();
173
+ }
174
+
175
+ public function deleteItem ($ key ): bool
176
+ {
177
+ return $ this ->parent ->deleteItem ($ key );
178
+ }
179
+
180
+ public function deleteItems (array $ keys ): bool
181
+ {
182
+ return $ this ->parent ->deleteItems ($ keys );
183
+ }
184
+
185
+ public function save (CacheItemInterface $ item ): bool
186
+ {
187
+ return $ this ->parent ->save ($ item );
188
+ }
189
+
190
+ public function saveDeferred (CacheItemInterface $ item ): bool
191
+ {
192
+ return $ this ->parent ->saveDeferred ($ item );
193
+ }
194
+
195
+ public function commit (): bool
196
+ {
197
+ return $ this ->parent ->commit ();
198
+ }
199
+ };
209
200
}
210
201
}
0 commit comments