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] [Versions 400 and 401]

   1  <?php
   2  
   3  namespace Box\Spout\Reader\CSV;
   4  
   5  use Box\Spout\Reader\IteratorInterface;
   6  
   7  /**
   8   * Class SheetIterator
   9   * Iterate over CSV unique "sheet".
  10   */
  11  class SheetIterator implements IteratorInterface
  12  {
  13      /** @var Sheet The CSV unique "sheet" */
  14      protected $sheet;
  15  
  16      /** @var bool Whether the unique "sheet" has already been read */
  17      protected $hasReadUniqueSheet = false;
  18  
  19      /**
  20       * @param Sheet $sheet Corresponding unique sheet
  21       */
  22      public function __construct($sheet)
  23      {
  24          $this->sheet = $sheet;
  25      }
  26  
  27      /**
  28       * Rewind the Iterator to the first element
  29       * @see http://php.net/manual/en/iterator.rewind.php
  30       *
  31       * @return void
  32       */
  33      public function rewind() : void
  34      {
  35          $this->hasReadUniqueSheet = false;
  36      }
  37  
  38      /**
  39       * Checks if current position is valid
  40       * @see http://php.net/manual/en/iterator.valid.php
  41       *
  42       * @return bool
  43       */
  44      public function valid() : bool
  45      {
  46          return (!$this->hasReadUniqueSheet);
  47      }
  48  
  49      /**
  50       * Move forward to next element
  51       * @see http://php.net/manual/en/iterator.next.php
  52       *
  53       * @return void
  54       */
  55      public function next() : void
  56      {
  57          $this->hasReadUniqueSheet = true;
  58      }
  59  
  60      /**
  61       * Return the current element
  62       * @see http://php.net/manual/en/iterator.current.php
  63       *
  64       * @return Sheet
  65       */
  66      public function current() : Sheet
  67      {
  68          return $this->sheet;
  69      }
  70  
  71      /**
  72       * Return the key of the current element
  73       * @see http://php.net/manual/en/iterator.key.php
  74       *
  75       * @return int
  76       */
  77      public function key() : int
  78      {
  79          return 1;
  80      }
  81  
  82      /**
  83       * Cleans up what was created to iterate over the object.
  84       *
  85       * @return void
  86       */
  87      public function end() : void
  88      {
  89          // do nothing
  90      }
  91  }