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\ODS\Creator;
   4  
   5  use Box\Spout\Common\Entity\Cell;
   6  use Box\Spout\Common\Entity\Row;
   7  use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
   8  use Box\Spout\Reader\Common\Entity\Options;
   9  use Box\Spout\Reader\Common\XMLProcessor;
  10  use Box\Spout\Reader\ODS\RowIterator;
  11  use Box\Spout\Reader\ODS\Sheet;
  12  use Box\Spout\Reader\ODS\SheetIterator;
  13  use Box\Spout\Reader\Wrapper\XMLReader;
  14  
  15  /**
  16   * Class EntityFactory
  17   * Factory to create entities
  18   */
  19  class InternalEntityFactory implements InternalEntityFactoryInterface
  20  {
  21      /** @var HelperFactory */
  22      private $helperFactory;
  23  
  24      /** @var ManagerFactory */
  25      private $managerFactory;
  26  
  27      /**
  28       * @param HelperFactory $helperFactory
  29       * @param ManagerFactory $managerFactory
  30       */
  31      public function __construct(HelperFactory $helperFactory, ManagerFactory $managerFactory)
  32      {
  33          $this->helperFactory = $helperFactory;
  34          $this->managerFactory = $managerFactory;
  35      }
  36  
  37      /**
  38       * @param string $filePath Path of the file to be read
  39       * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
  40       * @return SheetIterator
  41       */
  42      public function createSheetIterator($filePath, $optionsManager)
  43      {
  44          $escaper = $this->helperFactory->createStringsEscaper();
  45          $settingsHelper = $this->helperFactory->createSettingsHelper($this);
  46  
  47          return new SheetIterator($filePath, $optionsManager, $escaper, $settingsHelper, $this);
  48      }
  49  
  50      /**
  51       * @param XMLReader $xmlReader XML Reader
  52       * @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
  53       * @param string $sheetName Name of the sheet
  54       * @param bool $isSheetActive Whether the sheet was defined as active
  55       * @param bool $isSheetVisible Whether the sheet is visible
  56       * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
  57       * @return Sheet
  58       */
  59      public function createSheet($xmlReader, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible, $optionsManager)
  60      {
  61          $rowIterator = $this->createRowIterator($xmlReader, $optionsManager);
  62  
  63          return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible);
  64      }
  65  
  66      /**
  67       * @param XMLReader $xmlReader XML Reader
  68       * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
  69       * @return RowIterator
  70       */
  71      private function createRowIterator($xmlReader, $optionsManager)
  72      {
  73          $shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES);
  74          $cellValueFormatter = $this->helperFactory->createCellValueFormatter($shouldFormatDates);
  75          $xmlProcessor = $this->createXMLProcessor($xmlReader);
  76          $rowManager = $this->managerFactory->createRowManager($this);
  77  
  78          return new RowIterator($xmlReader, $optionsManager, $cellValueFormatter, $xmlProcessor, $rowManager, $this);
  79      }
  80  
  81      /**
  82       * @param Cell[] $cells
  83       * @return Row
  84       */
  85      public function createRow(array $cells = [])
  86      {
  87          return new Row($cells, null);
  88      }
  89  
  90      /**
  91       * @param mixed $cellValue
  92       * @return Cell
  93       */
  94      public function createCell($cellValue)
  95      {
  96          return new Cell($cellValue);
  97      }
  98  
  99      /**
 100       * @return XMLReader
 101       */
 102      public function createXMLReader()
 103      {
 104          return new XMLReader();
 105      }
 106  
 107      /**
 108       * @param $xmlReader
 109       * @return XMLProcessor
 110       */
 111      private function createXMLProcessor($xmlReader)
 112      {
 113          return new XMLProcessor($xmlReader);
 114      }
 115  
 116      /**
 117       * @return \ZipArchive
 118       */
 119      public function createZipArchive()
 120      {
 121          return new \ZipArchive();
 122      }
 123  }