Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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  }