PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/mailpoet/vendor-prefixed/doctrine/dbal/lib/Doctrine/DBAL/ForwardCompatibility/Result.php

https://gitlab.com/remyvianne/krowkaramel
PHP | 208 lines | 207 code | 0 blank | 1 comment | 16 complexity | e886ab4b49dc35915466cbbebc2a0f67 MD5 | raw file
  1. <?php
  2. namespace MailPoetVendor\Doctrine\DBAL\ForwardCompatibility;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoetVendor\Doctrine\DBAL\Driver;
  5. use MailPoetVendor\Doctrine\DBAL\Exception;
  6. use MailPoetVendor\Doctrine\DBAL\Exception\NoKeyValue;
  7. use MailPoetVendor\Doctrine\DBAL\ParameterType;
  8. use MailPoetVendor\Doctrine\Deprecations\Deprecation;
  9. use IteratorAggregate;
  10. use PDO;
  11. use ReturnTypeWillChange;
  12. use Traversable;
  13. use function array_shift;
  14. use function func_get_args;
  15. use function method_exists;
  16. class Result implements IteratorAggregate, DriverStatement, DriverResultStatement
  17. {
  18. private $stmt;
  19. public static function ensure(Driver\ResultStatement $stmt) : Result
  20. {
  21. if ($stmt instanceof Result) {
  22. return $stmt;
  23. }
  24. return new Result($stmt);
  25. }
  26. public function __construct(Driver\ResultStatement $stmt)
  27. {
  28. $this->stmt = $stmt;
  29. }
  30. #[\ReturnTypeWillChange]
  31. public function getIterator()
  32. {
  33. return $this->stmt;
  34. }
  35. public function closeCursor()
  36. {
  37. return $this->stmt->closeCursor();
  38. }
  39. public function columnCount()
  40. {
  41. return $this->stmt->columnCount();
  42. }
  43. public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
  44. {
  45. return $this->stmt->setFetchMode($fetchMode, $arg2, $arg3);
  46. }
  47. public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
  48. {
  49. Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', 'Result::fetch() is deprecated, use Result::fetchNumeric(), fetchAssociative() or fetchOne() instead.');
  50. return $this->stmt->fetch(...func_get_args());
  51. }
  52. public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
  53. {
  54. Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', 'Result::fetchAll() is deprecated, use Result::fetchAllNumeric(), fetchAllAssociative() or ' . 'fetchFirstColumn() instead.');
  55. return $this->stmt->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
  56. }
  57. public function fetchColumn($columnIndex = 0)
  58. {
  59. Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', 'Result::fetchColumn() is deprecated, use Result::fetchOne() instead.');
  60. return $this->stmt->fetchColumn($columnIndex);
  61. }
  62. public function fetchNumeric()
  63. {
  64. return $this->stmt->fetch(PDO::FETCH_NUM);
  65. }
  66. public function fetchAssociative()
  67. {
  68. return $this->stmt->fetch(PDO::FETCH_ASSOC);
  69. }
  70. public function fetchOne()
  71. {
  72. $row = $this->fetchNumeric();
  73. if ($row === \false) {
  74. return \false;
  75. }
  76. return $row[0];
  77. }
  78. public function fetchAllNumeric() : array
  79. {
  80. $rows = [];
  81. while (($row = $this->fetchNumeric()) !== \false) {
  82. $rows[] = $row;
  83. }
  84. return $rows;
  85. }
  86. public function fetchAllAssociative() : array
  87. {
  88. $rows = [];
  89. while (($row = $this->fetchAssociative()) !== \false) {
  90. $rows[] = $row;
  91. }
  92. return $rows;
  93. }
  94. public function fetchAllKeyValue() : array
  95. {
  96. $this->ensureHasKeyValue();
  97. $data = [];
  98. foreach ($this->fetchAllNumeric() as [$key, $value]) {
  99. $data[$key] = $value;
  100. }
  101. return $data;
  102. }
  103. public function fetchAllAssociativeIndexed() : array
  104. {
  105. $data = [];
  106. foreach ($this->fetchAllAssociative() as $row) {
  107. $data[array_shift($row)] = $row;
  108. }
  109. return $data;
  110. }
  111. public function fetchFirstColumn() : array
  112. {
  113. $rows = [];
  114. while (($row = $this->fetchOne()) !== \false) {
  115. $rows[] = $row;
  116. }
  117. return $rows;
  118. }
  119. public function iterateNumeric() : Traversable
  120. {
  121. while (($row = $this->fetchNumeric()) !== \false) {
  122. (yield $row);
  123. }
  124. }
  125. public function iterateAssociative() : Traversable
  126. {
  127. while (($row = $this->fetchAssociative()) !== \false) {
  128. (yield $row);
  129. }
  130. }
  131. public function iterateKeyValue() : Traversable
  132. {
  133. $this->ensureHasKeyValue();
  134. foreach ($this->iterateNumeric() as [$key, $value]) {
  135. (yield $key => $value);
  136. }
  137. }
  138. public function iterateAssociativeIndexed() : Traversable
  139. {
  140. foreach ($this->iterateAssociative() as $row) {
  141. (yield array_shift($row) => $row);
  142. }
  143. }
  144. public function iterateColumn() : Traversable
  145. {
  146. while (($value = $this->fetchOne()) !== \false) {
  147. (yield $value);
  148. }
  149. }
  150. public function rowCount()
  151. {
  152. if (method_exists($this->stmt, 'rowCount')) {
  153. return $this->stmt->rowCount();
  154. }
  155. throw Exception::notSupported('rowCount');
  156. }
  157. public function free() : void
  158. {
  159. $this->closeCursor();
  160. }
  161. private function ensureHasKeyValue() : void
  162. {
  163. $columnCount = $this->columnCount();
  164. if ($columnCount < 2) {
  165. throw NoKeyValue::fromColumnCount($columnCount);
  166. }
  167. }
  168. public function bindValue($param, $value, $type = ParameterType::STRING)
  169. {
  170. Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', 'Result::bindValue() is deprecated, no replacement.');
  171. if ($this->stmt instanceof Driver\Statement) {
  172. return $this->stmt->bindValue($param, $value, $type);
  173. }
  174. throw Exception::notSupported('bindValue');
  175. }
  176. public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
  177. {
  178. Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', 'Result::bindParam() is deprecated, no replacement.');
  179. if ($this->stmt instanceof Driver\Statement) {
  180. return $this->stmt->bindParam($param, $variable, $type, $length);
  181. }
  182. throw Exception::notSupported('bindParam');
  183. }
  184. public function errorCode()
  185. {
  186. Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', 'Result::errorCode() is deprecated, the error information is available via exceptions.');
  187. if ($this->stmt instanceof Driver\Statement) {
  188. return $this->stmt->errorCode();
  189. }
  190. throw Exception::notSupported('errorCode');
  191. }
  192. public function errorInfo()
  193. {
  194. Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', 'Result::errorInfo() is deprecated, the error information is available via exceptions.');
  195. if ($this->stmt instanceof Driver\Statement) {
  196. return $this->stmt->errorInfo();
  197. }
  198. throw Exception::notSupported('errorInfo');
  199. }
  200. public function execute($params = null)
  201. {
  202. Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', 'Result::execute() is deprecated, no replacement.');
  203. if ($this->stmt instanceof Driver\Statement) {
  204. return $this->stmt->execute($params);
  205. }
  206. throw Exception::notSupported('execute');
  207. }
  208. }