File tree Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Codefy \Framework \Support \Traits ;
6
+
7
+ use Codefy \Framework \Codefy ;
8
+
9
+ trait ContainerAware
10
+ {
11
+ public static function make (): static
12
+ {
13
+ return Codefy::$ PHP ->make (name: static ::class);
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Codefy \Framework \Support \Traits ;
6
+
7
+ use Codefy \Framework \Codefy ;
8
+ use Qubus \Exception \Exception ;
9
+
10
+ trait DbTransactionsAware
11
+ {
12
+ /**
13
+ * Determines whether class uses transaction.
14
+ */
15
+ protected bool $ useTransaction = false ;
16
+
17
+ /**
18
+ * Enable transaction in pipeline.
19
+ */
20
+ public function withTransaction (): static
21
+ {
22
+ $ this ->useTransaction = true ;
23
+
24
+ return $ this ;
25
+ }
26
+
27
+ /**
28
+ * Begin the transaction if enabled.
29
+ *
30
+ * @throws Exception
31
+ */
32
+ protected function beginTransaction (): void
33
+ {
34
+ if (!$ this ->useTransaction ) {
35
+ return ;
36
+ }
37
+
38
+ Codefy::$ PHP ->getDB ()->beginTransaction ();
39
+ }
40
+
41
+ /**
42
+ * Commit the transaction if enabled.
43
+ *
44
+ * @throws Exception
45
+ */
46
+ protected function commitTransaction (): void
47
+ {
48
+ if (!$ this ->useTransaction ) {
49
+ return ;
50
+ }
51
+
52
+ Codefy::$ PHP ->getDB ()->commit ();
53
+ }
54
+
55
+ /**
56
+ * Rollback the transaction if enabled.
57
+ *
58
+ * @throws Exception
59
+ */
60
+ protected function rollbackTransaction (): void
61
+ {
62
+ if (!$ this ->useTransaction ) {
63
+ return ;
64
+ }
65
+
66
+ Codefy::$ PHP ->getDB ()->rollback ();
67
+ }
68
+ }
You can’t perform that action at this time.
0 commit comments