1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11: * @link https://cakephp.org CakePHP(tm) Project
12: * @since 3.1.0
13: * @license https://opensource.org/licenses/mit-license.php MIT License
14: */
15: namespace Cake\Datasource;
16:
17: /**
18: * This interface defines the methods you can depend on in
19: * a connection.
20: *
21: * @method object getLogger() Get the current logger instance
22: * @method $this setLogger($logger) Set the current logger.
23: * @method bool supportsDynamicConstraints()
24: * @method \Cake\Database\Schema\Collection getSchemaCollection()
25: * @method \Cake\Database\Query newQuery()
26: * @method \Cake\Database\StatementInterface prepare($sql)
27: * @method \Cake\Database\StatementInterface execute($query, $params = [], array $types = [])
28: * @method $this enableQueryLogging($value)
29: * @method $this disableQueryLogging()
30: * @method $this disableSavePoints()
31: * @method bool isQueryLoggingEnabled()
32: * @method string quote($value, $type = null)
33: */
34: interface ConnectionInterface
35: {
36: /**
37: * Get the configuration name for this connection.
38: *
39: * @return string
40: */
41: public function configName();
42:
43: /**
44: * Get the configuration data used to create the connection.
45: *
46: * @return array
47: */
48: public function config();
49:
50: /**
51: * Executes a callable function inside a transaction, if any exception occurs
52: * while executing the passed callable, the transaction will be rolled back
53: * If the result of the callable function is `false`, the transaction will
54: * also be rolled back. Otherwise the transaction is committed after executing
55: * the callback.
56: *
57: * The callback will receive the connection instance as its first argument.
58: *
59: * @param callable $transaction The callback to execute within a transaction.
60: * @return mixed The return value of the callback.
61: * @throws \Exception Will re-throw any exception raised in $callback after
62: * rolling back the transaction.
63: */
64: public function transactional(callable $transaction);
65:
66: /**
67: * Run an operation with constraints disabled.
68: *
69: * Constraints should be re-enabled after the callback succeeds/fails.
70: *
71: * @param callable $operation The callback to execute within a transaction.
72: * @return mixed The return value of the callback.
73: * @throws \Exception Will re-throw any exception raised in $callback after
74: * rolling back the transaction.
75: */
76: public function disableConstraints(callable $operation);
77:
78: /**
79: * Enables or disables query logging for this connection.
80: *
81: * @param bool|null $enable whether to turn logging on or disable it.
82: * Use null to read current value.
83: * @return bool
84: */
85: public function logQueries($enable = null);
86:
87: /**
88: * Sets the logger object instance. When called with no arguments
89: * it returns the currently setup logger instance.
90: *
91: * @param object|null $instance logger object instance
92: * @return object logger instance
93: * @deprecated 3.5.0 Will be replaced by getLogger()/setLogger()
94: */
95: public function logger($instance = null);
96: }
97: