1 | <?php |
||
23 | final class LifecycleEventManager |
||
24 | { |
||
25 | /** @var DocumentManager */ |
||
26 | private $dm; |
||
27 | |||
28 | /** @var EventManager */ |
||
29 | private $evm; |
||
30 | |||
31 | /** @var UnitOfWork */ |
||
32 | private $uow; |
||
33 | |||
34 | 1827 | public function __construct(DocumentManager $dm, UnitOfWork $uow, EventManager $evm) |
|
35 | { |
||
36 | 1827 | $this->dm = $dm; |
|
37 | 1827 | $this->evm = $evm; |
|
38 | 1827 | $this->uow = $uow; |
|
39 | 1827 | } |
|
40 | |||
41 | /** |
||
42 | * @param mixed $id |
||
43 | * |
||
44 | * @return bool Returns whether the exceptionDisabled flag was set |
||
45 | */ |
||
46 | 9 | public function documentNotFound(object $proxy, $id) : bool |
|
47 | { |
||
48 | 9 | $eventArgs = new DocumentNotFoundEventArgs($proxy, $this->dm, $id); |
|
49 | 9 | $this->evm->dispatchEvent(Events::documentNotFound, $eventArgs); |
|
50 | |||
51 | 9 | return $eventArgs->isExceptionDisabled(); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Dispatches postCollectionLoad event. |
||
56 | */ |
||
57 | 179 | public function postCollectionLoad(PersistentCollectionInterface $coll) : void |
|
62 | |||
63 | /** |
||
64 | * Invokes postPersist callbacks and events for given document cascading them to embedded documents as well. |
||
65 | */ |
||
66 | 604 | public function postPersist(ClassMetadata $class, object $document) : void |
|
72 | |||
73 | /** |
||
74 | * Invokes postRemove callbacks and events for given document. |
||
75 | */ |
||
76 | 77 | public function postRemove(ClassMetadata $class, object $document) : void |
|
81 | |||
82 | /** |
||
83 | * Invokes postUpdate callbacks and events for given document. The same will be done for embedded documents owned |
||
84 | * by given document unless they were new in which case postPersist callbacks and events will be dispatched. |
||
85 | */ |
||
86 | 230 | public function postUpdate(ClassMetadata $class, object $document) : void |
|
92 | |||
93 | /** |
||
94 | * Invokes prePersist callbacks and events for given document. |
||
95 | */ |
||
96 | 663 | public function prePersist(ClassMetadata $class, object $document) : void |
|
101 | |||
102 | /** |
||
103 | * Invokes prePersist callbacks and events for given document. |
||
104 | */ |
||
105 | 83 | public function preRemove(ClassMetadata $class, object $document) : void |
|
110 | |||
111 | /** |
||
112 | * Invokes preUpdate callbacks and events for given document cascading them to embedded documents as well. |
||
113 | */ |
||
114 | 238 | public function preUpdate(ClassMetadata $class, object $document) : void |
|
123 | |||
124 | /** |
||
125 | * Cascades the preUpdate event to embedded documents. |
||
126 | */ |
||
127 | 238 | private function cascadePreUpdate(ClassMetadata $class, object $document) : void |
|
144 | |||
145 | /** |
||
146 | * Cascades the postUpdate and postPersist events to embedded documents. |
||
147 | */ |
||
148 | 230 | private function cascadePostUpdate(ClassMetadata $class, object $document) : void |
|
170 | |||
171 | /** |
||
172 | * Cascades the postPersist events to embedded documents. |
||
173 | */ |
||
174 | 604 | private function cascadePostPersist(ClassMetadata $class, object $document) : void |
|
187 | |||
188 | 664 | private function dispatchEvent(ClassMetadata $class, string $eventName, ?EventArgs $eventArgs = null) : void |
|
196 | } |
||
197 |