Cached.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Object used for caching the results of select queries. See [Results](/database/results#select-cached) for usage and examples.
  4. *
  5. * @package Kohana/Database
  6. * @category Query/Result
  7. * @author Kohana Team
  8. * @copyright (c) Kohana Team
  9. * @license https://koseven.ga/LICENSE.md
  10. */
  11. class Kohana_Database_Result_Cached extends Database_Result {
  12. public function __construct(array $result, $sql, $as_object = NULL)
  13. {
  14. parent::__construct($result, $sql, $as_object);
  15. // Find the number of rows in the result
  16. $this->_total_rows = count($result);
  17. }
  18. public function __destruct()
  19. {
  20. // Cached results do not use resources
  21. }
  22. public function cached()
  23. {
  24. return $this;
  25. }
  26. #[\ReturnTypeWillChange]
  27. public function seek($offset)
  28. {
  29. if ($this->offsetExists($offset))
  30. {
  31. $this->_current_row = $offset;
  32. return TRUE;
  33. }
  34. else
  35. {
  36. return FALSE;
  37. }
  38. }
  39. #[\ReturnTypeWillChange]
  40. public function current()
  41. {
  42. // Return an array of the row
  43. return $this->valid() ? $this->_result[$this->_current_row] : NULL;
  44. }
  45. } // End Database_Result_Cached