@@ -29,18 +29,28 @@ class MySQL implements Database {
29
29
private $ queryLoggers = 0 ;
30
30
/** @var MySQLExceptionInterpreter */
31
31
private $ exceptionInterpreter = 0 ;
32
-
32
+ /** @var array */
33
+ private $ options ;
34
+
33
35
/**
34
36
* @param PDO $pdo
37
+ * @param array $options
35
38
*/
36
- public function __construct (PDO $ pdo ) {
39
+ public function __construct (PDO $ pdo, array $ options = [] ) {
37
40
if ($ pdo ->getAttribute (PDO ::ATTR_ERRMODE ) === PDO ::ERRMODE_SILENT ) {
38
41
$ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
39
42
}
40
43
$ this ->pdo = $ pdo ;
41
44
$ this ->aliasRegistry = new AliasRegistry ();
42
45
$ this ->queryLoggers = new QueryLoggers ();
43
46
$ this ->exceptionInterpreter = new MySQLExceptionInterpreter ();
47
+ $ defaultOptions = [
48
+ 'select-options ' => [],
49
+ 'insert-options ' => [],
50
+ 'update-options ' => [],
51
+ 'delete-options ' => [],
52
+ ];
53
+ $ this ->options = array_merge ($ defaultOptions , $ options );
44
54
}
45
55
46
56
/**
@@ -182,7 +192,9 @@ public function quoteField($field) {
182
192
* @return Builder\RunnableSelect
183
193
*/
184
194
public function select (array $ fields = null ) {
185
- $ select = new Builder \RunnableSelect ($ this );
195
+ $ select = array_key_exists ('select-factory ' , $ this ->options )
196
+ ? call_user_func ($ this ->options ['select-factory ' ], $ this , $ this ->options ['select-options ' ])
197
+ : new Builder \RunnableSelect ($ this , $ this ->options ['select-options ' ]);
186
198
if ($ fields !== null ) {
187
199
$ select ->fields ($ fields );
188
200
}
@@ -194,7 +206,9 @@ public function select(array $fields = null) {
194
206
* @return Builder\RunnableInsert
195
207
*/
196
208
public function insert (array $ fields = null ) {
197
- $ insert = new Builder \RunnableInsert ($ this );
209
+ $ insert = array_key_exists ('insert-factory ' , $ this ->options )
210
+ ? call_user_func ($ this ->options ['insert-factory ' ], $ this , $ this ->options ['insert-options ' ])
211
+ : new Builder \RunnableInsert ($ this , $ this ->options ['insert-options ' ]);
198
212
if ($ fields !== null ) {
199
213
$ insert ->addAll ($ fields );
200
214
}
@@ -206,7 +220,9 @@ public function insert(array $fields = null) {
206
220
* @return Builder\RunnableUpdate
207
221
*/
208
222
public function update (array $ fields = null ) {
209
- $ update = new Builder \RunnableUpdate ($ this );
223
+ $ update = array_key_exists ('update-factory ' , $ this ->options )
224
+ ? call_user_func ($ this ->options ['update-factory ' ], $ this , $ this ->options ['update-options ' ])
225
+ : new Builder \RunnableUpdate ($ this , $ this ->options ['update-options ' ]);
210
226
if ($ fields !== null ) {
211
227
$ update ->setAll ($ fields );
212
228
}
@@ -217,7 +233,9 @@ public function update(array $fields = null) {
217
233
* @return Builder\RunnableDelete
218
234
*/
219
235
public function delete () {
220
- return new Builder \RunnableDelete ($ this );
236
+ return array_key_exists ('delete-factory ' , $ this ->options )
237
+ ? call_user_func ($ this ->options ['delete-factory ' ], $ this , $ this ->options ['delete-options ' ])
238
+ : new Builder \RunnableDelete ($ this , $ this ->options ['delete-options ' ]);
221
239
}
222
240
223
241
/**
0 commit comments