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\XLSX\Creator;
   4  
   5  use Box\Spout\Reader\Common\Manager\RowManager;
   6  use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
   7  use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
   8  use Box\Spout\Reader\XLSX\Manager\SheetManager;
   9  use Box\Spout\Reader\XLSX\Manager\StyleManager;
  10  use Box\Spout\Reader\XLSX\Manager\WorkbookRelationshipsManager;
  11  
  12  /**
  13   * Class ManagerFactory
  14   * Factory to create managers
  15   */
  16  class ManagerFactory
  17  {
  18      /** @var HelperFactory */
  19      private $helperFactory;
  20  
  21      /** @var CachingStrategyFactory */
  22      private $cachingStrategyFactory;
  23  
  24      /** @var WorkbookRelationshipsManager */
  25      private $cachedWorkbookRelationshipsManager;
  26  
  27      /**
  28       * @param HelperFactory $helperFactory Factory to create helpers
  29       * @param CachingStrategyFactory $cachingStrategyFactory Factory to create shared strings caching strategies
  30       */
  31      public function __construct(HelperFactory $helperFactory, CachingStrategyFactory $cachingStrategyFactory)
  32      {
  33          $this->helperFactory = $helperFactory;
  34          $this->cachingStrategyFactory = $cachingStrategyFactory;
  35      }
  36  
  37      /**
  38       * @param string $filePath Path of the XLSX file being read
  39       * @param string $tempFolder Temporary folder where the temporary files to store shared strings will be stored
  40       * @param InternalEntityFactory $entityFactory Factory to create entities
  41       * @return SharedStringsManager
  42       */
  43      public function createSharedStringsManager($filePath, $tempFolder, $entityFactory)
  44      {
  45          $workbookRelationshipsManager = $this->createWorkbookRelationshipsManager($filePath, $entityFactory);
  46  
  47          return new SharedStringsManager(
  48              $filePath,
  49              $tempFolder,
  50              $workbookRelationshipsManager,
  51              $entityFactory,
  52              $this->helperFactory,
  53              $this->cachingStrategyFactory
  54          );
  55      }
  56  
  57      /**
  58       * @param string $filePath Path of the XLSX file being read
  59       * @param InternalEntityFactory $entityFactory Factory to create entities
  60       * @return WorkbookRelationshipsManager
  61       */
  62      private function createWorkbookRelationshipsManager($filePath, $entityFactory)
  63      {
  64          if (!isset($this->cachedWorkbookRelationshipsManager)) {
  65              $this->cachedWorkbookRelationshipsManager = new WorkbookRelationshipsManager($filePath, $entityFactory);
  66          }
  67  
  68          return $this->cachedWorkbookRelationshipsManager;
  69      }
  70  
  71      /**
  72       * @param string $filePath Path of the XLSX file being read
  73       * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
  74       * @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager $sharedStringsManager Manages shared strings
  75       * @param InternalEntityFactory $entityFactory Factory to create entities
  76       * @return SheetManager
  77       */
  78      public function createSheetManager($filePath, $optionsManager, $sharedStringsManager, $entityFactory)
  79      {
  80          $escaper = $this->helperFactory->createStringsEscaper();
  81  
  82          return new SheetManager($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory);
  83      }
  84  
  85      /**
  86       * @param string $filePath Path of the XLSX file being read
  87       * @param InternalEntityFactory $entityFactory Factory to create entities
  88       * @return StyleManager
  89       */
  90      public function createStyleManager($filePath, $entityFactory)
  91      {
  92          $workbookRelationshipsManager = $this->createWorkbookRelationshipsManager($filePath, $entityFactory);
  93  
  94          return new StyleManager($filePath, $workbookRelationshipsManager, $entityFactory);
  95      }
  96  
  97      /**
  98       * @param InternalEntityFactory $entityFactory Factory to create entities
  99       * @return RowManager
 100       */
 101      public function createRowManager($entityFactory)
 102      {
 103          return new RowManager($entityFactory);
 104      }
 105  }