88
99namespace Ibexa \Core \Persistence \Doctrine ;
1010
11+ use Doctrine \Common \EventManager ;
1112use Doctrine \DBAL \Connection ;
1213use Doctrine \ORM \Cache ;
1314use Doctrine \ORM \Configuration ;
1415use Doctrine \ORM \EntityManagerInterface ;
1516use Doctrine \ORM \EntityRepository ;
1617use Doctrine \ORM \Internal \Hydration \AbstractHydrator ;
1718use Doctrine \ORM \Mapping \ClassMetadata ;
18- use Doctrine \ORM \Mapping \ClassMetadataFactory ;
1919use Doctrine \ORM \NativeQuery ;
2020use Doctrine \ORM \Proxy \ProxyFactory ;
2121use Doctrine \ORM \Query ;
2424use Doctrine \ORM \Query \ResultSetMapping ;
2525use Doctrine \ORM \QueryBuilder ;
2626use Doctrine \ORM \UnitOfWork ;
27+ use Doctrine \Persistence \Mapping \ClassMetadataFactory ;
2728use Ibexa \Bundle \Core \Entity \EntityManagerFactory ;
2829use Ibexa \Contracts \Core \MVC \EventSubscriber \ConfigScopeChangeSubscriber ;
2930use Ibexa \Core \MVC \Symfony \Event \ScopeChangeEvent ;
3031use Symfony \Contracts \Service \ResetInterface ;
3132
3233/**
3334 * @internal
34- *
35- * SiteAccessAwareEntityManager is a cross-compatible class supporting doctrine/persistence v2 and v3.
3635 */
3736final class SiteAccessAwareEntityManager implements EntityManagerInterface, ConfigScopeChangeSubscriber, ResetInterface
3837{
@@ -80,10 +79,7 @@ public function transactional($func)
8079 return $ this ->getWrapped ()->transactional ($ func );
8180 }
8281
83- /**
84- * @return mixed
85- */
86- public function wrapInTransaction (callable $ func )
82+ public function wrapInTransaction (callable $ func ): mixed
8783 {
8884 return $ this ->getWrapped ()->wrapInTransaction ($ func );
8985 }
@@ -129,6 +125,8 @@ public function createQueryBuilder(): QueryBuilder
129125 * @param class-string<T> $entityName
130126 *
131127 * @return T|null
128+ *
129+ * @throws \Doctrine\ORM\Exception\ORMException
132130 */
133131 public function getReference ($ entityName , $ id ): ?object
134132 {
@@ -171,7 +169,7 @@ public function lock($entity, $lockMode, $lockVersion = null): void
171169 $ this ->getWrapped ()->lock ($ entity , $ lockMode , $ lockVersion );
172170 }
173171
174- public function getEventManager (): \ Doctrine \ Common \ EventManager
172+ public function getEventManager (): EventManager
175173 {
176174 return $ this ->getWrapped ()->getEventManager ();
177175 }
@@ -231,36 +229,27 @@ public function find($className, $id): ?object
231229 return $ this ->getWrapped ()->find ($ className , $ id );
232230 }
233231
234- /**
235- * @param object $object
236- */
237- public function persist ($ object ): void
232+ public function persist (object $ object ): void
238233 {
239234 $ this ->getWrapped ()->persist ($ object );
240235 }
241236
242- public function remove ($ object ): void
237+ public function remove (object $ object ): void
243238 {
244239 $ this ->getWrapped ()->remove ($ object );
245240 }
246241
247- /**
248- * @param string|null $objectName
249- */
250- public function clear ($ objectName = null ): void
242+ public function clear (): void
251243 {
252- $ this ->getWrapped ()->clear ($ objectName );
244+ $ this ->getWrapped ()->clear ();
253245 }
254246
255- /**
256- * @param object $object
257- */
258- public function detach ($ object ): void
247+ public function detach (object $ object ): void
259248 {
260249 $ this ->getWrapped ()->detach ($ object );
261250 }
262251
263- public function refresh ($ object , ?int $ lockMode = null ): void
252+ public function refresh (object $ object , ?int $ lockMode = null ): void
264253 {
265254 $ this ->getWrapped ()->refresh ($ object , $ lockMode );
266255 }
@@ -270,62 +259,48 @@ public function flush(): void
270259 $ this ->getWrapped ()->flush ();
271260 }
272261
262+ /**
263+ * @template T of object
264+ *
265+ * @param class-string<T> $className
266+ *
267+ * @return EntityRepository<T>
268+ */
273269 public function getRepository ($ className ): EntityRepository
274270 {
275271 return $ this ->getWrapped ()->getRepository ($ className );
276272 }
277273
274+ /**
275+ * @template T of object
276+ *
277+ * @param class-string<T> $className
278+ *
279+ * @return ClassMetadata<T>
280+ */
278281 public function getClassMetadata ($ className ): ClassMetadata
279282 {
280283 return $ this ->getWrapped ()->getClassMetadata ($ className );
281284 }
282285
283286 public function getMetadataFactory (): ClassMetadataFactory
284287 {
288+ /** @phpstan-var ClassMetadataFactory<\Doctrine\Persistence\Mapping\ClassMetadata<object>> */
285289 return $ this ->getWrapped ()->getMetadataFactory ();
286290 }
287291
288- /**
289- * @param object $obj
290- */
291- public function initializeObject ($ obj ): void
292+ public function initializeObject (object $ obj ): void
292293 {
293294 $ this ->getWrapped ()->initializeObject ($ obj );
294295 }
295296
296- /**
297- * @param mixed $value
298- */
299- public function isUninitializedObject ($ value ): bool
297+ public function isUninitializedObject (mixed $ value ): bool
300298 {
301- $ entityManager = $ this ->getWrapped ();
302-
303- // workaround for doctrine/persistence v2 and v3 cross-compatibility
304- return method_exists ($ entityManager , 'isUninitializedObject ' )
305- ? $ entityManager ->isUninitializedObject ($ value )
306- : false ;
299+ return $ this ->getWrapped ()->isUninitializedObject ($ value );
307300 }
308301
309- /**
310- * @param object $object
311- */
312- public function contains ($ object ): bool
302+ public function contains (object $ object ): bool
313303 {
314304 return $ this ->getWrapped ()->contains ($ object );
315305 }
316-
317- /**
318- * @param object $object
319- *
320- * @return object|null
321- */
322- public function merge ($ object )
323- {
324- $ entityManager = $ this ->getWrapped ();
325-
326- // workaround for doctrine/persistence v2 and v3 cross-compatibility
327- return method_exists ($ entityManager , 'merge ' )
328- ? $ entityManager ->merge ($ object )
329- : null ;
330- }
331306}
0 commit comments