1 | <?php |
||
38 | abstract class AbstractCollectionPersister implements CachedCollectionPersister |
||
39 | { |
||
40 | /** |
||
41 | * @var \Doctrine\ORM\UnitOfWork |
||
42 | */ |
||
43 | protected $uow; |
||
44 | |||
45 | /** |
||
46 | * @var \Doctrine\ORM\Mapping\ClassMetadataFactory |
||
47 | */ |
||
48 | protected $metadataFactory; |
||
49 | |||
50 | /** |
||
51 | * @var \Doctrine\ORM\Persisters\Collection\CollectionPersister |
||
52 | */ |
||
53 | protected $persister; |
||
54 | |||
55 | /** |
||
56 | * @var \Doctrine\ORM\Mapping\ClassMetadata |
||
57 | */ |
||
58 | protected $sourceEntity; |
||
59 | |||
60 | /** |
||
61 | * @var \Doctrine\ORM\Mapping\ClassMetadata |
||
62 | */ |
||
63 | protected $targetEntity; |
||
64 | |||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $association; |
||
69 | |||
70 | /** |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $queuedCache = array(); |
||
74 | |||
75 | /** |
||
76 | * @var \Doctrine\ORM\Cache\Region |
||
77 | */ |
||
78 | protected $region; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | */ |
||
83 | protected $regionName; |
||
84 | |||
85 | /** |
||
86 | * @var \Doctrine\ORM\Cache\CollectionHydrator |
||
87 | */ |
||
88 | protected $hydrator; |
||
89 | |||
90 | /** |
||
91 | * @var \Doctrine\ORM\Cache\Logging\CacheLogger |
||
92 | */ |
||
93 | protected $cacheLogger; |
||
94 | |||
95 | /** |
||
96 | * @param \Doctrine\ORM\Persisters\Collection\CollectionPersister $persister The collection persister that will be cached. |
||
97 | * @param \Doctrine\ORM\Cache\Region $region The collection region. |
||
98 | * @param \Doctrine\ORM\EntityManagerInterface $em The entity manager. |
||
99 | * @param array $association The association mapping. |
||
100 | */ |
||
101 | 114 | public function __construct(CollectionPersister $persister, Region $region, EntityManagerInterface $em, array $association) |
|
102 | { |
||
103 | 114 | $configuration = $em->getConfiguration(); |
|
104 | 114 | $cacheConfig = $configuration->getSecondLevelCacheConfiguration(); |
|
105 | 114 | $cacheFactory = $cacheConfig->getCacheFactory(); |
|
106 | |||
107 | 114 | $this->region = $region; |
|
108 | 114 | $this->persister = $persister; |
|
109 | 114 | $this->association = $association; |
|
110 | 114 | $this->regionName = $region->getName(); |
|
111 | 114 | $this->uow = $em->getUnitOfWork(); |
|
112 | 114 | $this->metadataFactory = $em->getMetadataFactory(); |
|
113 | 114 | $this->cacheLogger = $cacheConfig->getCacheLogger(); |
|
114 | 114 | $this->hydrator = $cacheFactory->buildCollectionHydrator($em, $association); |
|
115 | 114 | $this->sourceEntity = $em->getClassMetadata($association['sourceEntity']); |
|
116 | 114 | $this->targetEntity = $em->getClassMetadata($association['targetEntity']); |
|
117 | 114 | } |
|
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | 61 | public function getCacheRegion() |
|
123 | { |
||
124 | 61 | return $this->region; |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | public function getSourceEntityMetadata() |
||
131 | { |
||
132 | return $this->sourceEntity; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function getTargetEntityMetadata() |
||
139 | { |
||
140 | return $this->targetEntity; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @param \Doctrine\ORM\PersistentCollection $collection |
||
145 | * @param \Doctrine\ORM\Cache\CollectionCacheKey $key |
||
146 | * |
||
147 | * @return \Doctrine\ORM\PersistentCollection|null |
||
148 | */ |
||
149 | 16 | public function loadCollectionCache(PersistentCollection $collection, CollectionCacheKey $key) |
|
150 | { |
||
151 | 16 | if (($cache = $this->region->get($key)) === null) { |
|
152 | 12 | return null; |
|
153 | } |
||
154 | |||
155 | 15 | if (($cache = $this->hydrator->loadCacheEntry($this->sourceEntity, $key, $cache, $collection)) === null) { |
|
|
|||
156 | return null; |
||
157 | } |
||
158 | |||
159 | 15 | return $cache; |
|
160 | } |
||
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | 42 | public function storeCollectionCache(CollectionCacheKey $key, $elements) |
|
205 | |||
206 | /** |
||
207 | * {@inheritdoc} |
||
208 | */ |
||
209 | 3 | public function contains(PersistentCollection $collection, $element) |
|
213 | |||
214 | /** |
||
215 | * {@inheritdoc} |
||
216 | */ |
||
217 | 3 | public function containsKey(PersistentCollection $collection, $key) |
|
221 | |||
222 | /** |
||
223 | * {@inheritdoc} |
||
224 | */ |
||
225 | 4 | public function count(PersistentCollection $collection) |
|
237 | |||
238 | /** |
||
239 | * {@inheritdoc} |
||
240 | */ |
||
241 | 3 | public function get(PersistentCollection $collection, $index) |
|
245 | |||
246 | /** |
||
247 | * {@inheritdoc} |
||
248 | */ |
||
249 | 3 | public function removeElement(PersistentCollection $collection, $element) |
|
259 | |||
260 | /** |
||
261 | * {@inheritdoc} |
||
262 | */ |
||
263 | 3 | public function slice(PersistentCollection $collection, $offset, $length = null) |
|
267 | |||
268 | /** |
||
269 | * {@inheritDoc} |
||
270 | */ |
||
271 | public function loadCriteria(PersistentCollection $collection, Criteria $criteria) |
||
275 | |||
276 | /** |
||
277 | * Clears cache entries related to the current collection |
||
278 | * |
||
279 | * @param PersistentCollection $collection |
||
280 | */ |
||
281 | protected function evictCollectionCache(PersistentCollection $collection) |
||
295 | |||
296 | /** |
||
297 | * @param string $targetEntity |
||
298 | * @param object $element |
||
299 | */ |
||
300 | protected function evictElementCache($targetEntity, $element) |
||
313 | } |
||
314 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.