ConnectionInterface.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * This interface defines the methods you can depend on in
  18. * a connection.
  19. *
  20. * @method object getLogger() Get the current logger instance
  21. * @method $this setLogger($logger) Set the current logger.
  22. * @method bool supportsDynamicConstraints()
  23. * @method \Cake\Database\Schema\Collection getSchemaCollection()
  24. * @method \Cake\Database\Query newQuery()
  25. * @method \Cake\Database\StatementInterface prepare($sql)
  26. * @method \Cake\Database\StatementInterface execute($query, $params = [], array $types = [])
  27. * @method $this enableQueryLogging($value)
  28. * @method $this disableQueryLogging()
  29. * @method $this disableSavePoints()
  30. * @method bool isQueryLoggingEnabled()
  31. * @method string quote($value, $type = null)
  32. */
  33. interface ConnectionInterface
  34. {
  35. /**
  36. * Get the configuration name for this connection.
  37. *
  38. * @return string
  39. */
  40. public function configName();
  41. /**
  42. * Get the configuration data used to create the connection.
  43. *
  44. * @return array
  45. */
  46. public function config();
  47. /**
  48. * Executes a callable function inside a transaction, if any exception occurs
  49. * while executing the passed callable, the transaction will be rolled back
  50. * If the result of the callable function is `false`, the transaction will
  51. * also be rolled back. Otherwise the transaction is committed after executing
  52. * the callback.
  53. *
  54. * The callback will receive the connection instance as its first argument.
  55. *
  56. * @param callable $transaction The callback to execute within a transaction.
  57. * @return mixed The return value of the callback.
  58. * @throws \Exception Will re-throw any exception raised in $callback after
  59. * rolling back the transaction.
  60. */
  61. public function transactional(callable $transaction);
  62. /**
  63. * Run an operation with constraints disabled.
  64. *
  65. * Constraints should be re-enabled after the callback succeeds/fails.
  66. *
  67. * @param callable $operation The callback to execute within a transaction.
  68. * @return mixed The return value of the callback.
  69. * @throws \Exception Will re-throw any exception raised in $callback after
  70. * rolling back the transaction.
  71. */
  72. public function disableConstraints(callable $operation);
  73. /**
  74. * Enables or disables query logging for this connection.
  75. *
  76. * @param bool|null $enable whether to turn logging on or disable it.
  77. * Use null to read current value.
  78. * @return bool
  79. */
  80. public function logQueries($enable = null);
  81. /**
  82. * Sets the logger object instance. When called with no arguments
  83. * it returns the currently setup logger instance.
  84. *
  85. * @param object|null $instance logger object instance
  86. * @return object logger instance
  87. * @deprecated 3.5.0 Will be replaced by getLogger()/setLogger()
  88. */
  89. public function logger($instance = null);
  90. }