1
|
|
|
<?php |
2
|
|
|
/******************************************************************************* |
3
|
|
|
* This file is part of the GraphQL Bundle package. |
4
|
|
|
* |
5
|
|
|
* (c) YnloUltratech <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
******************************************************************************/ |
10
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Test\FixtureLoader\Cache; |
12
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
14
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
15
|
|
|
use Doctrine\ORM\Query\ResultSetMapping; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* This is a proxy entity manager to save in cache all |
19
|
|
|
* fixtures without do a real persist or flush |
20
|
|
|
* @see CachedFixtureExecutor |
21
|
|
|
*/ |
22
|
|
|
class CachedFixtureEntityManager implements EntityManagerInterface |
23
|
|
|
{ |
24
|
|
|
protected $cachedForPersist = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var EntityManagerInterface |
28
|
|
|
*/ |
29
|
|
|
protected $em; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param EntityManagerInterface $em |
33
|
|
|
*/ |
34
|
21 |
|
public function __construct(EntityManagerInterface $em) |
35
|
|
|
{ |
36
|
21 |
|
$this->em = $em; |
37
|
21 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
1 |
|
public function getCachedForPersist(): array |
43
|
|
|
{ |
44
|
1 |
|
return $this->cachedForPersist; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
*/ |
50
|
|
|
public function find($className, $id) |
51
|
|
|
{ |
52
|
|
|
return $this->em->find($className, $id); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritDoc} |
57
|
|
|
*/ |
58
|
1 |
|
public function persist($object) |
59
|
|
|
{ |
60
|
1 |
|
$oid = spl_object_hash($object); |
61
|
1 |
|
$this->cachedForPersist[$oid] = $object; |
62
|
1 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
21 |
|
public function persistReal($object) |
68
|
|
|
{ |
69
|
21 |
|
$this->em->persist($object); |
70
|
21 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritDoc} |
74
|
|
|
*/ |
75
|
|
|
public function remove($object) |
76
|
|
|
{ |
77
|
|
|
$this->em->remove($object); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritDoc} |
82
|
|
|
*/ |
83
|
|
|
public function merge($object) |
84
|
|
|
{ |
85
|
|
|
return $this->em->merge($object); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritDoc} |
90
|
|
|
*/ |
91
|
1 |
|
public function clear($objectName = null) |
92
|
|
|
{ |
93
|
1 |
|
$this->em->clear($objectName); |
94
|
1 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritDoc} |
98
|
|
|
*/ |
99
|
|
|
public function detach($object) |
100
|
|
|
{ |
101
|
|
|
$this->em->detach($object); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritDoc} |
106
|
|
|
*/ |
107
|
|
|
public function refresh($object) |
108
|
|
|
{ |
109
|
|
|
$this->em->refresh($object); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritDoc} |
114
|
|
|
*/ |
115
|
1 |
|
public function flush($entity = null) |
116
|
|
|
{ |
117
|
|
|
|
118
|
1 |
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritDoc} |
122
|
|
|
*/ |
123
|
|
|
public function flushReal() |
124
|
|
|
{ |
125
|
|
|
$this->em->flush(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* {@inheritDoc} |
130
|
|
|
*/ |
131
|
|
|
public function getRepository($className) |
132
|
|
|
{ |
133
|
|
|
return $this->em->getRepository($className); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritDoc} |
138
|
|
|
*/ |
139
|
21 |
|
public function getClassMetadata($className): ClassMetadata |
140
|
|
|
{ |
141
|
21 |
|
return $this->em->getClassMetadata($className); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* {@inheritDoc} |
146
|
|
|
*/ |
147
|
21 |
|
public function getMetadataFactory() |
148
|
|
|
{ |
149
|
21 |
|
return $this->em->getMetadataFactory(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* {@inheritDoc} |
154
|
|
|
*/ |
155
|
|
|
public function initializeObject($obj) |
156
|
|
|
{ |
157
|
|
|
$this->em->initializeObject($obj); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* {@inheritDoc} |
162
|
|
|
*/ |
163
|
|
|
public function contains($object) |
164
|
|
|
{ |
165
|
|
|
return $this->em->contains($object); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
*{@inheritDoc} |
170
|
|
|
*/ |
171
|
|
|
public function getCache() |
172
|
|
|
{ |
173
|
|
|
return $this->em->getCache(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
*{@inheritDoc} |
178
|
|
|
*/ |
179
|
21 |
|
public function getConnection() |
180
|
|
|
{ |
181
|
21 |
|
return $this->em->getConnection(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
*{@inheritDoc} |
186
|
|
|
*/ |
187
|
|
|
public function getExpressionBuilder() |
188
|
|
|
{ |
189
|
|
|
return $this->em->getExpressionBuilder(); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
*{@inheritDoc} |
194
|
|
|
*/ |
195
|
|
|
public function beginTransaction() |
196
|
|
|
{ |
197
|
|
|
$this->em->beginTransaction(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
*{@inheritDoc} |
202
|
|
|
*/ |
203
|
21 |
|
public function transactional($func) |
204
|
|
|
{ |
205
|
21 |
|
$this->cachedForPersist = []; |
206
|
21 |
|
$this->em->transactional($func); |
207
|
21 |
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
*{@inheritDoc} |
211
|
|
|
*/ |
212
|
|
|
public function commit() |
213
|
|
|
{ |
214
|
|
|
$this->em->commit(); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
*{@inheritDoc} |
219
|
|
|
*/ |
220
|
|
|
public function rollback() |
221
|
|
|
{ |
222
|
|
|
$this->em->rollback(); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
*{@inheritDoc} |
227
|
|
|
*/ |
228
|
|
|
public function createQuery($dql = '') |
229
|
|
|
{ |
230
|
|
|
return $this->em->createQuery($dql); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
*{@inheritDoc} |
235
|
|
|
*/ |
236
|
|
|
public function createNamedQuery($name) |
237
|
|
|
{ |
238
|
|
|
return $this->em->createNamedQuery($name); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
*{@inheritDoc} |
243
|
|
|
*/ |
244
|
|
|
public function createNativeQuery($sql, ResultSetMapping $rsm) |
245
|
|
|
{ |
246
|
|
|
return $this->em->createNativeQuery($sql, $rsm); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
*{@inheritDoc} |
251
|
|
|
*/ |
252
|
|
|
public function createNamedNativeQuery($name) |
253
|
|
|
{ |
254
|
|
|
return $this->em->createNamedNativeQuery($name); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
*{@inheritDoc} |
259
|
|
|
*/ |
260
|
|
|
public function createQueryBuilder() |
261
|
|
|
{ |
262
|
|
|
return $this->em->createQueryBuilder(); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
*{@inheritDoc} |
267
|
|
|
*/ |
268
|
|
|
public function getReference($entityName, $id) |
269
|
|
|
{ |
270
|
|
|
return $this->em->getReference($entityName, $id); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
*{@inheritDoc} |
275
|
|
|
*/ |
276
|
|
|
public function getPartialReference($entityName, $identifier) |
277
|
|
|
{ |
278
|
|
|
return $this->em->getPartialReference($entityName, $identifier); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
*{@inheritDoc} |
283
|
|
|
*/ |
284
|
|
|
public function close() |
285
|
|
|
{ |
286
|
|
|
$this->em->close(); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
*{@inheritDoc} |
291
|
|
|
*/ |
292
|
|
|
public function copy($entity, $deep = false) |
293
|
|
|
{ |
294
|
|
|
return $this->em->copy($entity, $deep); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
*{@inheritDoc} |
299
|
|
|
*/ |
300
|
|
|
public function lock($entity, $lockMode, $lockVersion = null) |
301
|
|
|
{ |
302
|
|
|
$this->em->lock($entity, $lockMode, $lockVersion); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
*{@inheritDoc} |
307
|
|
|
*/ |
308
|
21 |
|
public function getEventManager() |
309
|
|
|
{ |
310
|
21 |
|
return $this->em->getEventManager(); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
*{@inheritDoc} |
315
|
|
|
*/ |
316
|
21 |
|
public function getConfiguration() |
317
|
|
|
{ |
318
|
21 |
|
return $this->em->getConfiguration(); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
*{@inheritDoc} |
323
|
|
|
*/ |
324
|
|
|
public function isOpen() |
325
|
|
|
{ |
326
|
|
|
return $this->em->isOpen(); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
*{@inheritDoc} |
331
|
|
|
*/ |
332
|
|
|
public function getUnitOfWork() |
333
|
|
|
{ |
334
|
|
|
return $this->em->getUnitOfWork(); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
*{@inheritDoc} |
339
|
|
|
*/ |
340
|
|
|
public function getHydrator($hydrationMode) |
341
|
|
|
{ |
342
|
|
|
return $this->em->getHydrator($hydrationMode); |
|
|
|
|
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
*{@inheritDoc} |
347
|
|
|
*/ |
348
|
|
|
public function newHydrator($hydrationMode) |
349
|
|
|
{ |
350
|
|
|
return $this->em->newHydrator($hydrationMode); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
*{@inheritDoc} |
355
|
|
|
*/ |
356
|
|
|
public function getProxyFactory() |
357
|
|
|
{ |
358
|
|
|
return $this->em->getProxyFactory(); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
*{@inheritDoc} |
363
|
|
|
*/ |
364
|
|
|
public function getFilters() |
365
|
|
|
{ |
366
|
|
|
return $this->em->getFilters(); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
*{@inheritDoc} |
371
|
|
|
*/ |
372
|
|
|
public function isFiltersStateClean() |
373
|
|
|
{ |
374
|
|
|
return $this->em->isFiltersStateClean(); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
*{@inheritDoc} |
379
|
|
|
*/ |
380
|
|
|
public function hasFilters() |
381
|
|
|
{ |
382
|
|
|
return $this->em->hasFilters(); |
383
|
|
|
} |
384
|
|
|
} |
385
|
|
|
|