1 | <?php |
||
22 | final class LifecycleEventManager |
||
23 | { |
||
24 | /** @var DocumentManager */ |
||
25 | private $dm; |
||
26 | |||
27 | /** @var EventManager */ |
||
28 | private $evm; |
||
29 | |||
30 | /** @var UnitOfWork */ |
||
31 | private $uow; |
||
32 | |||
33 | 1081 | public function __construct(DocumentManager $dm, UnitOfWork $uow, EventManager $evm) |
|
39 | |||
40 | /** |
||
41 | * @param mixed $id |
||
42 | * |
||
43 | * @return bool Returns whether the exceptionDisabled flag was set |
||
44 | */ |
||
45 | public function documentNotFound(object $proxy, $id) : bool |
||
46 | { |
||
47 | $eventArgs = new DocumentNotFoundEventArgs($proxy, $this->dm, $id); |
||
48 | $this->evm->dispatchEvent(Events::documentNotFound, $eventArgs); |
||
49 | |||
50 | return $eventArgs->isExceptionDisabled(); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Dispatches postCollectionLoad event. |
||
55 | */ |
||
56 | 2 | public function postCollectionLoad(PersistentCollectionInterface $coll) : void |
|
61 | |||
62 | /** |
||
63 | * Invokes postPersist callbacks and events for given document cascading them to embedded documents as well. |
||
64 | */ |
||
65 | public function postPersist(ClassMetadata $class, object $document) : void |
||
66 | { |
||
67 | $class->invokeLifecycleCallbacks(Events::postPersist, $document, [new LifecycleEventArgs($document, $this->dm)]); |
||
68 | $this->evm->dispatchEvent(Events::postPersist, new LifecycleEventArgs($document, $this->dm)); |
||
69 | $this->cascadePostPersist($class, $document); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Invokes postRemove callbacks and events for given document. |
||
74 | */ |
||
75 | public function postRemove(ClassMetadata $class, object $document) : void |
||
76 | { |
||
77 | $class->invokeLifecycleCallbacks(Events::postRemove, $document, [new LifecycleEventArgs($document, $this->dm)]); |
||
78 | $this->evm->dispatchEvent(Events::postRemove, new LifecycleEventArgs($document, $this->dm)); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Invokes postUpdate callbacks and events for given document. The same will be done for embedded documents owned |
||
83 | * by given document unless they were new in which case postPersist callbacks and events will be dispatched. |
||
84 | */ |
||
85 | public function postUpdate(ClassMetadata $class, object $document) : void |
||
86 | { |
||
87 | $class->invokeLifecycleCallbacks(Events::postUpdate, $document, [new LifecycleEventArgs($document, $this->dm)]); |
||
88 | $this->evm->dispatchEvent(Events::postUpdate, new LifecycleEventArgs($document, $this->dm)); |
||
89 | $this->cascadePostUpdate($class, $document); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Invokes prePersist callbacks and events for given document. |
||
94 | */ |
||
95 | 75 | public function prePersist(ClassMetadata $class, object $document) : void |
|
100 | |||
101 | /** |
||
102 | * Invokes prePersist callbacks and events for given document. |
||
103 | */ |
||
104 | public function preRemove(ClassMetadata $class, object $document) : void |
||
109 | |||
110 | /** |
||
111 | * Invokes preUpdate callbacks and events for given document cascading them to embedded documents as well. |
||
112 | */ |
||
113 | public function preUpdate(ClassMetadata $class, object $document) : void |
||
122 | |||
123 | /** |
||
124 | * Cascades the preUpdate event to embedded documents. |
||
125 | */ |
||
126 | private function cascadePreUpdate(ClassMetadata $class, object $document) : void |
||
143 | |||
144 | /** |
||
145 | * Cascades the postUpdate and postPersist events to embedded documents. |
||
146 | */ |
||
147 | private function cascadePostUpdate(ClassMetadata $class, object $document) : void |
||
169 | |||
170 | /** |
||
171 | * Cascades the postPersist events to embedded documents. |
||
172 | */ |
||
173 | private function cascadePostPersist(ClassMetadata $class, object $document) : void |
||
186 | } |
||
187 |