1 | <?php |
||
14 | class Connector |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * The default PDO connection options. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $options = [ |
||
23 | PDO::ATTR_CASE => PDO::CASE_NATURAL, |
||
24 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
||
25 | PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, |
||
26 | PDO::ATTR_STRINGIFY_FETCHES => false, |
||
27 | PDO::ATTR_EMULATE_PREPARES => false, |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Create a new PDO connection. |
||
32 | * |
||
33 | * @param string $dsn |
||
34 | * @param array $config |
||
35 | * @param array $options |
||
36 | * @return \PDO |
||
37 | */ |
||
38 | public function createConnection($dsn, array $config, array $options) |
||
54 | |||
55 | /** |
||
56 | * Create a new PDO connection instance. |
||
57 | * |
||
58 | * @param string $dsn |
||
59 | * @param string $username |
||
60 | * @param string $password |
||
61 | * @param array $options |
||
62 | * @return \PDO |
||
63 | */ |
||
64 | protected function createPdoConnection($dsn, $username, $password, $options) |
||
68 | |||
69 | /** |
||
70 | * Determine if the connection is persistent. |
||
71 | * |
||
72 | * @param array $options |
||
73 | * @return bool |
||
74 | */ |
||
75 | protected function isPersistentConnection($options) |
||
80 | |||
81 | /** |
||
82 | * Handle an exception that occurred during connect execution. |
||
83 | * |
||
84 | * @param \Exception $e |
||
85 | * @param string $dsn |
||
86 | * @param string $username |
||
87 | * @param string $password |
||
88 | * @param array $options |
||
89 | * @return \PDO |
||
90 | * |
||
91 | * @throws \Exception |
||
92 | */ |
||
93 | protected function tryAgainIfCausedByLostConnection(\Exception $e, $dsn, $username, $password, $options) |
||
101 | |||
102 | /** |
||
103 | * Get the PDO options based on the configuration. |
||
104 | * |
||
105 | * @param array $config |
||
106 | * @return array |
||
107 | */ |
||
108 | public function getOptions(array $config) |
||
114 | |||
115 | /** |
||
116 | * Get the default PDO connection options. |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | public function getDefaultOptions() |
||
124 | |||
125 | /** |
||
126 | * Set the default PDO connection options. |
||
127 | * |
||
128 | * @param array $options |
||
129 | * @return void |
||
130 | */ |
||
131 | public function setDefaultOptions(array $options) |
||
135 | /** |
||
136 | * Determine if the given exception was caused by a lost connection. |
||
137 | * |
||
138 | * @param \Exception $e |
||
139 | * @return bool |
||
140 | */ |
||
141 | protected function causedByLostConnection(\Exception $e) |
||
159 | } |