summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Internal/HydrationCompleteHandler.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Internal/HydrationCompleteHandler.php
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/Internal/HydrationCompleteHandler.php')
-rw-r--r--vendor/doctrine/orm/src/Internal/HydrationCompleteHandler.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Internal/HydrationCompleteHandler.php b/vendor/doctrine/orm/src/Internal/HydrationCompleteHandler.php
new file mode 100644
index 0000000..e0fe342
--- /dev/null
+++ b/vendor/doctrine/orm/src/Internal/HydrationCompleteHandler.php
@@ -0,0 +1,64 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Internal;
6
7use Doctrine\ORM\EntityManagerInterface;
8use Doctrine\ORM\Event\ListenersInvoker;
9use Doctrine\ORM\Event\PostLoadEventArgs;
10use Doctrine\ORM\Events;
11use Doctrine\ORM\Mapping\ClassMetadata;
12
13/**
14 * Class, which can handle completion of hydration cycle and produce some of tasks.
15 * In current implementation triggers deferred postLoad event.
16 */
17final class HydrationCompleteHandler
18{
19 /** @var mixed[][] */
20 private array $deferredPostLoadInvocations = [];
21
22 public function __construct(
23 private readonly ListenersInvoker $listenersInvoker,
24 private readonly EntityManagerInterface $em,
25 ) {
26 }
27
28 /**
29 * Method schedules invoking of postLoad entity to the very end of current hydration cycle.
30 */
31 public function deferPostLoadInvoking(ClassMetadata $class, object $entity): void
32 {
33 $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postLoad);
34
35 if ($invoke === ListenersInvoker::INVOKE_NONE) {
36 return;
37 }
38
39 $this->deferredPostLoadInvocations[] = [$class, $invoke, $entity];
40 }
41
42 /**
43 * This method should be called after any hydration cycle completed.
44 *
45 * Method fires all deferred invocations of postLoad events
46 */
47 public function hydrationComplete(): void
48 {
49 $toInvoke = $this->deferredPostLoadInvocations;
50 $this->deferredPostLoadInvocations = [];
51
52 foreach ($toInvoke as $classAndEntity) {
53 [$class, $invoke, $entity] = $classAndEntity;
54
55 $this->listenersInvoker->invoke(
56 $class,
57 Events::postLoad,
58 $entity,
59 new PostLoadEventArgs($entity, $this->em),
60 $invoke,
61 );
62 }
63 }
64}