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.
   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  }