diff --git a/core/lib/Drupal/Core/Database/Php7StatementInterface.php b/core/lib/Drupal/Core/Database/Php7StatementInterface.php new file mode 100644 index 0000000000..549575b4b1 --- /dev/null +++ b/core/lib/Drupal/Core/Database/Php7StatementInterface.php @@ -0,0 +1,31 @@ +doFetch($mode, $cursor_orientation, $cursor_offset); + } + +} diff --git a/core/lib/Drupal/Core/Database/Php8StatementInterface.php b/core/lib/Drupal/Core/Database/Php8StatementInterface.php new file mode 100644 index 0000000000..b2b33c3e5a --- /dev/null +++ b/core/lib/Drupal/Core/Database/Php8StatementInterface.php @@ -0,0 +1,31 @@ +doFetch($mode, $cursor_orientation, $cursor_offset); + } + +} diff --git a/core/lib/Drupal/Core/Database/StatementEmpty.php b/core/lib/Drupal/Core/Database/StatementEmpty.php index 0d89ea3f4f..fb29d046ff 100644 --- a/core/lib/Drupal/Core/Database/StatementEmpty.php +++ b/core/lib/Drupal/Core/Database/StatementEmpty.php @@ -2,6 +2,13 @@ namespace Drupal\Core\Database; +if (PHP_VERSION_ID >= 80000) { + class_alias('\Drupal\Core\Database\Php8StatementTrait', '\Drupal\Core\Database\StatementTrait'); +} +else { + class_alias('\Drupal\Core\Database\Php7StatementTrait', '\Drupal\Core\Database\StatementTrait'); +} + /** * Empty implementation of a database statement. * @@ -14,6 +21,7 @@ * @see \Drupal\search\SearchQuery */ class StatementEmpty implements \Iterator, StatementInterface { + use StatementTrait; /** * Is rowCount() execution allowed. @@ -52,9 +60,15 @@ public function rowCount() { public function setFetchMode($mode, $a1 = NULL, $a2 = []) {} /** - * {@inheritdoc} + * Fetches the next row from a result set. + * + * @return + * A result. + * + * @see \Drupal\Core\Database\Php7StatementTrait::fetch() + * @see \Drupal\Core\Database\Php8StatementTrait::fetch() */ - public function fetch(int $mode = \PDO::FETCH_BOTH, int $cursor_orientation = \PDO::FETCH_ORI_NEXT, int $cursor_offset = 0) { + public function doFetch() { return NULL; } diff --git a/core/lib/Drupal/Core/Database/StatementInterface.php b/core/lib/Drupal/Core/Database/StatementInterface.php index f61e25e915..13b6cce7a6 100644 --- a/core/lib/Drupal/Core/Database/StatementInterface.php +++ b/core/lib/Drupal/Core/Database/StatementInterface.php @@ -2,6 +2,13 @@ namespace Drupal\Core\Database; +if (PHP_VERSION_ID >= 80000) { + class_alias('\Drupal\Core\Database\Php8StatementInterface', '\Drupal\Core\Database\StatementInterfaceBase'); +} +else { + class_alias('\Drupal\Core\Database\Php7StatementInterface', '\Drupal\Core\Database\StatementInterfaceBase'); +} + /** * Represents a prepared statement. * @@ -18,7 +25,7 @@ * * @ingroup database */ -interface StatementInterface extends \Traversable { +interface StatementInterface extends StatementInterfaceBase, \Traversable { /** * Constructs a new PDOStatement object. @@ -92,25 +99,6 @@ public function rowCount(); */ public function setFetchMode($mode, $a1 = NULL, $a2 = []); - /** - * Fetches the next row from a result set. - * - * See http://php.net/manual/pdo.constants.php for the definition of the - * constants used. - * - * @param $mode - * One of the PDO::FETCH_* constants. - * Default to what was specified by setFetchMode(). - * @param $cursor_orientation - * Not implemented in all database drivers, don't use. - * @param $cursor_offset - * Not implemented in all database drivers, don't use. - * - * @return - * A result, formatted according to $mode. - */ - public function fetch(int $mode = \PDO::FETCH_BOTH, int $cursor_orientation = \PDO::FETCH_ORI_NEXT, int $cursor_offset = 0); - /** * Returns a single field from the next record of a result set. * diff --git a/core/lib/Drupal/Core/Database/StatementPrefetch.php b/core/lib/Drupal/Core/Database/StatementPrefetch.php index aae3e1bf3b..3c46426772 100644 --- a/core/lib/Drupal/Core/Database/StatementPrefetch.php +++ b/core/lib/Drupal/Core/Database/StatementPrefetch.php @@ -2,6 +2,13 @@ namespace Drupal\Core\Database; +if (PHP_VERSION_ID >= 80000) { + class_alias('\Drupal\Core\Database\Php8StatementTrait', '\Drupal\Core\Database\StatementTrait'); +} +else { + class_alias('\Drupal\Core\Database\Php7StatementTrait', '\Drupal\Core\Database\StatementTrait'); +} + /** * An implementation of StatementInterface that prefetches all data. * @@ -9,6 +16,7 @@ * every row it is possible to manipulate those results. */ class StatementPrefetch implements \Iterator, StatementInterface { + use StatementTrait; /** * The query string. @@ -373,12 +381,22 @@ public function rowCount() { } /** - * {@inheritdoc} + * Fetches the next row from a result set. + * + * @param int $mode + * One of the PDO::FETCH_* constants. Default to what was specified by + * setFetchMode(). + * + * @return + * A result. + * + * @see \Drupal\Core\Database\Php7StatementTrait::fetch() + * @see \Drupal\Core\Database\Php8StatementTrait::fetch() */ - public function fetch(int $mode = \PDO::FETCH_BOTH, int $cursor_orientation = \PDO::FETCH_ORI_NEXT, int $cursor_offset = 0) { + public function doFetch($mode) { if (isset($this->currentRow)) { // Set the fetch parameter. - $this->fetchStyle = isset($fetch_style) ? $fetch_style : $this->defaultFetchStyle; + $this->fetchStyle = isset($mode) ? $mode : $this->defaultFetchStyle; $this->fetchOptions = $this->defaultFetchOptions; // Grab the row in the format specified above.