Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401]

   1  <?php
   2  
   3  namespace Box\Spout\Writer\XLSX\Creator;
   4  
   5  use Box\Spout\Common\Manager\OptionsManagerInterface;
   6  use Box\Spout\Writer\Common\Creator\InternalEntityFactory;
   7  use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
   8  use Box\Spout\Writer\Common\Entity\Options;
   9  use Box\Spout\Writer\Common\Manager\RowManager;
  10  use Box\Spout\Writer\Common\Manager\SheetManager;
  11  use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
  12  use Box\Spout\Writer\XLSX\Manager\SharedStringsManager;
  13  use Box\Spout\Writer\XLSX\Manager\Style\StyleManager;
  14  use Box\Spout\Writer\XLSX\Manager\Style\StyleRegistry;
  15  use Box\Spout\Writer\XLSX\Manager\WorkbookManager;
  16  use Box\Spout\Writer\XLSX\Manager\WorksheetManager;
  17  
  18  /**
  19   * Class ManagerFactory
  20   * Factory for managers needed by the XLSX Writer
  21   */
  22  class ManagerFactory implements ManagerFactoryInterface
  23  {
  24      /** @var InternalEntityFactory */
  25      protected $entityFactory;
  26  
  27      /** @var HelperFactory $helperFactory */
  28      protected $helperFactory;
  29  
  30      /**
  31       * @param InternalEntityFactory $entityFactory
  32       * @param HelperFactory $helperFactory
  33       */
  34      public function __construct(InternalEntityFactory $entityFactory, HelperFactory $helperFactory)
  35      {
  36          $this->entityFactory = $entityFactory;
  37          $this->helperFactory = $helperFactory;
  38      }
  39  
  40      /**
  41       * @param OptionsManagerInterface $optionsManager
  42       * @return WorkbookManager
  43       */
  44      public function createWorkbookManager(OptionsManagerInterface $optionsManager)
  45      {
  46          $workbook = $this->entityFactory->createWorkbook();
  47  
  48          $fileSystemHelper = $this->helperFactory->createSpecificFileSystemHelper($optionsManager, $this->entityFactory);
  49          $fileSystemHelper->createBaseFilesAndFolders();
  50  
  51          $xlFolder = $fileSystemHelper->getXlFolder();
  52          $sharedStringsManager = $this->createSharedStringsManager($xlFolder);
  53  
  54          $styleMerger = $this->createStyleMerger();
  55          $styleManager = $this->createStyleManager($optionsManager);
  56          $worksheetManager = $this->createWorksheetManager($optionsManager, $styleManager, $styleMerger, $sharedStringsManager);
  57  
  58          return new WorkbookManager(
  59              $workbook,
  60              $optionsManager,
  61              $worksheetManager,
  62              $styleManager,
  63              $styleMerger,
  64              $fileSystemHelper,
  65              $this->entityFactory,
  66              $this
  67          );
  68      }
  69  
  70      /**
  71       * @param OptionsManagerInterface $optionsManager
  72       * @param StyleManager $styleManager
  73       * @param StyleMerger $styleMerger
  74       * @param SharedStringsManager $sharedStringsManager
  75       * @return WorksheetManager
  76       */
  77      private function createWorksheetManager(
  78          OptionsManagerInterface $optionsManager,
  79          StyleManager $styleManager,
  80          StyleMerger $styleMerger,
  81          SharedStringsManager $sharedStringsManager
  82      ) {
  83          $rowManager = $this->createRowManager();
  84          $stringsEscaper = $this->helperFactory->createStringsEscaper();
  85          $stringsHelper = $this->helperFactory->createStringHelper();
  86  
  87          return new WorksheetManager(
  88              $optionsManager,
  89              $rowManager,
  90              $styleManager,
  91              $styleMerger,
  92              $sharedStringsManager,
  93              $stringsEscaper,
  94              $stringsHelper,
  95              $this->entityFactory
  96          );
  97      }
  98  
  99      /**
 100       * @return SheetManager
 101       */
 102      public function createSheetManager()
 103      {
 104          $stringHelper = $this->helperFactory->createStringHelper();
 105  
 106          return new SheetManager($stringHelper);
 107      }
 108  
 109      /**
 110       * @return RowManager
 111       */
 112      public function createRowManager()
 113      {
 114          return new RowManager();
 115      }
 116  
 117      /**
 118       * @param OptionsManagerInterface $optionsManager
 119       * @return StyleManager
 120       */
 121      private function createStyleManager(OptionsManagerInterface $optionsManager)
 122      {
 123          $styleRegistry = $this->createStyleRegistry($optionsManager);
 124  
 125          return new StyleManager($styleRegistry);
 126      }
 127  
 128      /**
 129       * @param OptionsManagerInterface $optionsManager
 130       * @return StyleRegistry
 131       */
 132      private function createStyleRegistry(OptionsManagerInterface $optionsManager)
 133      {
 134          $defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE);
 135  
 136          return new StyleRegistry($defaultRowStyle);
 137      }
 138  
 139      /**
 140       * @return StyleMerger
 141       */
 142      private function createStyleMerger()
 143      {
 144          return new StyleMerger();
 145      }
 146  
 147      /**
 148       * @param string $xlFolder Path to the "xl" folder
 149       * @return SharedStringsManager
 150       */
 151      private function createSharedStringsManager($xlFolder)
 152      {
 153          $stringEscaper = $this->helperFactory->createStringsEscaper();
 154  
 155          return new SharedStringsManager($xlFolder, $stringEscaper);
 156      }
 157  }