Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  
   3  namespace Box\Spout\Reader\Common\Creator;
   4  
   5  use Box\Spout\Common\Exception\UnsupportedTypeException;
   6  use Box\Spout\Common\Type;
   7  use Box\Spout\Reader\ReaderInterface;
   8  
   9  /**
  10   * Class ReaderEntityFactory
  11   * Factory to create external entities
  12   */
  13  class ReaderEntityFactory
  14  {
  15      /**
  16       * Creates a reader by file extension
  17       *
  18       * @param string $path The path to the spreadsheet file. Supported extensions are .csv, .ods and .xlsx
  19       * @throws \Box\Spout\Common\Exception\UnsupportedTypeException
  20       * @return ReaderInterface
  21       */
  22      public static function createReaderFromFile(string $path)
  23      {
  24          return ReaderFactory::createFromFile($path);
  25      }
  26  
  27      /**
  28       * This creates an instance of a CSV reader
  29       *
  30       * @return \Box\Spout\Reader\CSV\Reader
  31       */
  32      public static function createCSVReader()
  33      {
  34          try {
  35              return ReaderFactory::createFromType(Type::CSV);
  36          } catch (UnsupportedTypeException $e) {
  37              // should never happen
  38          }
  39      }
  40  
  41      /**
  42       * This creates an instance of a XLSX reader
  43       *
  44       * @return \Box\Spout\Reader\XLSX\Reader
  45       */
  46      public static function createXLSXReader()
  47      {
  48          try {
  49              return ReaderFactory::createFromType(Type::XLSX);
  50          } catch (UnsupportedTypeException $e) {
  51              // should never happen
  52          }
  53      }
  54  
  55      /**
  56       * This creates an instance of a ODS reader
  57       *
  58       * @return \Box\Spout\Reader\ODS\Reader
  59       */
  60      public static function createODSReader()
  61      {
  62          try {
  63              return ReaderFactory::createFromType(Type::ODS);
  64          } catch (UnsupportedTypeException $e) {
  65              // should never happen
  66          }
  67      }
  68  }