[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/spout/src/Spout/Reader/ODS/ -> Reader.php (source)

   1  <?php
   2  
   3  namespace Box\Spout\Reader\ODS;
   4  
   5  use Box\Spout\Common\Exception\IOException;
   6  use Box\Spout\Reader\AbstractReader;
   7  
   8  /**
   9   * Class Reader
  10   * This class provides support to read data from a ODS file
  11   *
  12   * @package Box\Spout\Reader\ODS
  13   */
  14  class Reader extends AbstractReader
  15  {
  16      /** @var \ZipArchive */
  17      protected $zip;
  18  
  19      /** @var SheetIterator To iterator over the ODS sheets */
  20      protected $sheetIterator;
  21  
  22      /**
  23       * Returns whether stream wrappers are supported
  24       *
  25       * @return bool
  26       */
  27      protected function doesSupportStreamWrapper()
  28      {
  29          return false;
  30      }
  31  
  32      /**
  33       * Opens the file at the given file path to make it ready to be read.
  34       *
  35       * @param  string $filePath Path of the file to be read
  36       * @return void
  37       * @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read
  38       * @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
  39       */
  40      protected function openReader($filePath)
  41      {
  42          $this->zip = new \ZipArchive();
  43  
  44          if ($this->zip->open($filePath) === true) {
  45              $this->sheetIterator = new SheetIterator($filePath);
  46          } else {
  47              throw new IOException("Could not open $filePath for reading.");
  48          }
  49      }
  50  
  51      /**
  52       * Returns an iterator to iterate over sheets.
  53       *
  54       * @return SheetIterator To iterate over sheets
  55       */
  56      public function getConcreteSheetIterator()
  57      {
  58          return $this->sheetIterator;
  59      }
  60  
  61      /**
  62       * Closes the reader. To be used after reading the file.
  63       *
  64       * @return void
  65       */
  66      protected function closeReader()
  67      {
  68          if ($this->zip) {
  69              $this->zip->close();
  70          }
  71      }
  72  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1