Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Reader;
   4  
   5  use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
   6  use PhpOffice\PhpSpreadsheet\Shared\File;
   7  
   8  abstract class BaseReader implements IReader
   9  {
  10      /**
  11       * Read data only?
  12       * Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
  13       *        or whether it should read both data and formatting.
  14       *
  15       * @var bool
  16       */
  17      protected $readDataOnly = false;
  18  
  19      /**
  20       * Read empty cells?
  21       * Identifies whether the Reader should read data values for cells all cells, or should ignore cells containing
  22       *         null value or empty string.
  23       *
  24       * @var bool
  25       */
  26      protected $readEmptyCells = true;
  27  
  28      /**
  29       * Read charts that are defined in the workbook?
  30       * Identifies whether the Reader should read the definitions for any charts that exist in the workbook;.
  31       *
  32       * @var bool
  33       */
  34      protected $includeCharts = false;
  35  
  36      /**
  37       * Restrict which sheets should be loaded?
  38       * This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
  39       *
  40       * @var array of string
  41       */
  42      protected $loadSheetsOnly;
  43  
  44      /**
  45       * IReadFilter instance.
  46       *
  47       * @var IReadFilter
  48       */
  49      protected $readFilter;
  50  
  51      protected $fileHandle;
  52  
  53      /**
  54       * @var XmlScanner
  55       */
  56      protected $securityScanner;
  57  
  58      public function __construct()
  59      {
  60          $this->readFilter = new DefaultReadFilter();
  61      }
  62  
  63      public function getReadDataOnly()
  64      {
  65          return $this->readDataOnly;
  66      }
  67  
  68      public function setReadDataOnly($pValue)
  69      {
  70          $this->readDataOnly = (bool) $pValue;
  71  
  72          return $this;
  73      }
  74  
  75      public function getReadEmptyCells()
  76      {
  77          return $this->readEmptyCells;
  78      }
  79  
  80      public function setReadEmptyCells($pValue)
  81      {
  82          $this->readEmptyCells = (bool) $pValue;
  83  
  84          return $this;
  85      }
  86  
  87      public function getIncludeCharts()
  88      {
  89          return $this->includeCharts;
  90      }
  91  
  92      public function setIncludeCharts($pValue)
  93      {
  94          $this->includeCharts = (bool) $pValue;
  95  
  96          return $this;
  97      }
  98  
  99      public function getLoadSheetsOnly()
 100      {
 101          return $this->loadSheetsOnly;
 102      }
 103  
 104      public function setLoadSheetsOnly($value)
 105      {
 106          if ($value === null) {
 107              return $this->setLoadAllSheets();
 108          }
 109  
 110          $this->loadSheetsOnly = is_array($value) ? $value : [$value];
 111  
 112          return $this;
 113      }
 114  
 115      public function setLoadAllSheets()
 116      {
 117          $this->loadSheetsOnly = null;
 118  
 119          return $this;
 120      }
 121  
 122      public function getReadFilter()
 123      {
 124          return $this->readFilter;
 125      }
 126  
 127      public function setReadFilter(IReadFilter $pValue)
 128      {
 129          $this->readFilter = $pValue;
 130  
 131          return $this;
 132      }
 133  
 134      public function getSecurityScanner()
 135      {
 136          if (property_exists($this, 'securityScanner')) {
 137              return $this->securityScanner;
 138          }
 139  
 140          return null;
 141      }
 142  
 143      /**
 144       * Open file for reading.
 145       *
 146       * @param string $pFilename
 147       *
 148       * @throws Exception
 149       */
 150      protected function openFile($pFilename)
 151      {
 152          File::assertFile($pFilename);
 153  
 154          // Open file
 155          $this->fileHandle = fopen($pFilename, 'r');
 156          if ($this->fileHandle === false) {
 157              throw new Exception('Could not open file ' . $pFilename . ' for reading.');
 158          }
 159      }
 160  }