File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44class Connection
55{
6+ /**
7+ * @var Configuration
8+ */
69 private $ configuration ;
710
11+ /**
12+ * @var \PDO|null
13+ */
814 private $ dbh ;
915
16+ /**
17+ * Connection constructor.
18+ * @param Configuration $configuration
19+ */
1020 public function __construct (Configuration $ configuration )
1121 {
1222 $ this ->configuration = $ configuration ;
1323 }
1424
15- public function getDbh (): \PDO
25+ /**
26+ * @return \PDO|null
27+ * @throws \Exception
28+ */
29+ public function getDbh ()
1630 {
17- $ this ->connect ();
18-
1931 return $ this ->dbh ;
2032 }
2133
34+ /**
35+ * @return string
36+ */
2237 public function getDsn (): string
2338 {
2439 $ dsn = "" ;
@@ -82,6 +97,10 @@ public function getDsn(): string
8297 return $ dsn ;
8398 }
8499
100+ /**
101+ * @return Connection
102+ * @throws \Exception
103+ */
85104 public function connect (): Connection
86105 {
87106 try {
@@ -90,19 +109,26 @@ public function connect(): Connection
90109 $ this ->dbh ->setAttribute (\PDO ::ATTR_EMULATE_PREPARES ,true );
91110
92111 } catch (\PDOException $ e ) {
93- echo ' Connection failed: ' . $ e ->getMessage ();
112+ throw new \ Exception ( $ e ->getMessage (), $ e -> getCode () );
94113 }
95114
96115 return $ this ;
97116 }
98117
118+ /**
119+ * @return Connection
120+ */
99121 public function disconnect (): Connection
100122 {
101123 $ this ->dbh = null ;
102124
103125 return $ this ;
104126 }
105127
128+ /**
129+ * @return Connection
130+ * @throws \Exception
131+ */
106132 public function reconnect (): Connection
107133 {
108134 $ this ->disconnect ();
You can’t perform that action at this time.
0 commit comments