@@ -29,18 +29,28 @@ class MySQL implements Database {
2929 private $ queryLoggers = 0 ;
3030 /** @var MySQLExceptionInterpreter */
3131 private $ exceptionInterpreter = 0 ;
32-
32+ /** @var array */
33+ private $ options ;
34+
3335 /**
3436 * @param PDO $pdo
37+ * @param array $options
3538 */
36- public function __construct (PDO $ pdo ) {
39+ public function __construct (PDO $ pdo, array $ options = [] ) {
3740 if ($ pdo ->getAttribute (PDO ::ATTR_ERRMODE ) === PDO ::ERRMODE_SILENT ) {
3841 $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
3942 }
4043 $ this ->pdo = $ pdo ;
4144 $ this ->aliasRegistry = new AliasRegistry ();
4245 $ this ->queryLoggers = new QueryLoggers ();
4346 $ 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 );
4454 }
4555
4656 /**
@@ -182,7 +192,9 @@ public function quoteField($field) {
182192 * @return Builder\RunnableSelect
183193 */
184194 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 ' ]);
186198 if ($ fields !== null ) {
187199 $ select ->fields ($ fields );
188200 }
@@ -194,7 +206,9 @@ public function select(array $fields = null) {
194206 * @return Builder\RunnableInsert
195207 */
196208 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 ' ]);
198212 if ($ fields !== null ) {
199213 $ insert ->addAll ($ fields );
200214 }
@@ -206,7 +220,9 @@ public function insert(array $fields = null) {
206220 * @return Builder\RunnableUpdate
207221 */
208222 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 ' ]);
210226 if ($ fields !== null ) {
211227 $ update ->setAll ($ fields );
212228 }
@@ -217,7 +233,9 @@ public function update(array $fields = null) {
217233 * @return Builder\RunnableDelete
218234 */
219235 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 ' ]);
221239 }
222240
223241 /**
0 commit comments