TransactionEvent.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\persistence;
12 
14 
15 /**
16  * TransactionEvent instances are fired at different phases
17  * of a transaction. Note that depending on the phase, some of
18  * the properties may be null, because they are not initialized yet
19  * (e.g. controller).
20  *
21  * @author ingo herwig <ingo@wemove.com>
22  */
23 class TransactionEvent extends Event {
24 
25  const NAME = __CLASS__;
26 
27  /**
28  * A BEFORE_COMMIT event occurs before the transaction is committed.
29  */
30  const BEFORE_COMMIT = 'BEFORE_COMMIT';
31 
32  /**
33  * An AFTER_COMMIT event occurs after the transaction is committed.
34  */
35  const AFTER_COMMIT = 'AFTER_COMMIT';
36 
37  /**
38  * An AFTER_ROLLBACK event occurs after the transaction is rolled back.
39  */
40  const AFTER_ROLLBACK = 'AFTER_ROLLBACK';
41 
42  private $phase = null;
43  private $insertedOids = [];
44  private $updatedOids = [];
45  private $deletedOids = [];
46 
47  /**
48  * Constructor.
49  * @param $phase The phase at which the event occurred.
50  * @param $insertedOids Associative array mapping old to new object id strings
51  * @param $updatedOids Array of object id strings of updated objects
52  * @param $deletedOids Array of object id strings of deleted objects
53  */
54  public function __construct($phase, array $insertedOids=[], array $updatedOids=[], array $deletedOids=[]) {
55  $this->phase = $phase;
56  $this->insertedOids = $insertedOids;
57  $this->updatedOids = $updatedOids;
58  $this->deletedOids = $deletedOids;
59  }
60 
61  /**
62  * Get the phase at which the event occurred.
63  * @return String
64  */
65  public function getPhase() {
66  return $this->phase;
67  }
68 
69  /**
70  * Get the map of oids of inserted objects.
71  * NOTE: This property is available after commit only
72  * @return Map of oid changes (key: oid string before commit, value: oid string after commit)
73  */
74  public function getInsertedOids() {
75  return $this->insertedOids;
76  }
77 
78  /**
79  * Get the list of oids of updated objects.
80  * NOTE: This property is available after commit only
81  * @return Array of oid strings
82  */
83  public function getUpdatedOids() {
84  return $this->updatedOids;
85  }
86 
87  /**
88  * Get the list of oids of deleted objects.
89  * NOTE: This property is available after commit only
90  * @return Array of oid strings
91  */
92  public function getDeletedOids() {
93  return $this->deletedOids;
94  }
95 }
96 ?>
__construct($phase, array $insertedOids=[], array $updatedOids=[], array $deletedOids=[])
Constructor.
Persistence layer related interfaces and classes.
Definition: namespaces.php:42
Event is the base class for all events.
Definition: Event.php:18
const BEFORE_COMMIT
A BEFORE_COMMIT event occurs before the transaction is committed.
const AFTER_COMMIT
An AFTER_COMMIT event occurs after the transaction is committed.
TransactionEvent instances are fired at different phases of a transaction.
getPhase()
Get the phase at which the event occurred.
getUpdatedOids()
Get the list of oids of updated objects.
getDeletedOids()
Get the list of oids of deleted objects.
getInsertedOids()
Get the map of oids of inserted objects.
const AFTER_ROLLBACK
An AFTER_ROLLBACK event occurs after the transaction is rolled back.