Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Worksheet;
   4  
   5  use PhpOffice\PhpSpreadsheet\Spreadsheet;
   6  
   7  class Iterator implements \Iterator
   8  {
   9      /**
  10       * Spreadsheet to iterate.
  11       *
  12       * @var Spreadsheet
  13       */
  14      private $subject;
  15  
  16      /**
  17       * Current iterator position.
  18       *
  19       * @var int
  20       */
  21      private $position = 0;
  22  
  23      /**
  24       * Create a new worksheet iterator.
  25       *
  26       * @param Spreadsheet $subject
  27       */
  28      public function __construct(Spreadsheet $subject)
  29      {
  30          // Set subject
  31          $this->subject = $subject;
  32      }
  33  
  34      /**
  35       * Destructor.
  36       */
  37      public function __destruct()
  38      {
  39          unset($this->subject);
  40      }
  41  
  42      /**
  43       * Rewind iterator.
  44       */
  45      public function rewind()
  46      {
  47          $this->position = 0;
  48      }
  49  
  50      /**
  51       * Current Worksheet.
  52       *
  53       * @return Worksheet
  54       */
  55      public function current()
  56      {
  57          return $this->subject->getSheet($this->position);
  58      }
  59  
  60      /**
  61       * Current key.
  62       *
  63       * @return int
  64       */
  65      public function key()
  66      {
  67          return $this->position;
  68      }
  69  
  70      /**
  71       * Next value.
  72       */
  73      public function next()
  74      {
  75          ++$this->position;
  76      }
  77  
  78      /**
  79       * Are there more Worksheet instances available?
  80       *
  81       * @return bool
  82       */
  83      public function valid()
  84      {
  85          return $this->position < $this->subject->getSheetCount() && $this->position >= 0;
  86      }
  87  }