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