Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

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