| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Box\Spout\Reader\XLSX\Creator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Box\Spout\Reader\Common\Creator\EntityFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Box\Spout\Reader\Common\Entity\Options; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Box\Spout\Reader\Common\XMLProcessor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Box\Spout\Reader\Wrapper\XMLReader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Box\Spout\Reader\XLSX\Manager\SharedStringsManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Box\Spout\Reader\XLSX\RowIterator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Box\Spout\Reader\XLSX\Sheet; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Box\Spout\Reader\XLSX\SheetIterator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use MongoDB\Driver\Manager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Class EntityFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * Factory to create entities | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class EntityFactory implements EntityFactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** @var HelperFactory */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     private $helperFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** @var ManagerFactory */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private $managerFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @param ManagerFactory $managerFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @param HelperFactory $helperFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 78 |  |     public function __construct(ManagerFactory $managerFactory, HelperFactory $helperFactory) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 78 |  |         $this->managerFactory = $managerFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 78 |  |         $this->helperFactory = $helperFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 78 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |      * @param SharedStringsManager $sharedStringsManager Manages shared strings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @return SheetIterator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 34 |  |     public function createSheetIterator($filePath, $optionsManager, $sharedStringsManager) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 34 |  |         $sheetManager = $this->managerFactory->createSheetManager($filePath, $optionsManager, $sharedStringsManager, $this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 34 |  |         return new SheetIterator($sheetManager); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @param string $filePath Path of the XLSX file being read | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @param string $sheetName Name of the sheet | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @param bool $isSheetActive Whether the sheet was defined as active | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @param SharedStringsManager $sharedStringsManager Manages shared strings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @return Sheet | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 33 |  |     public function createSheet( | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         $filePath, | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $sheetDataXMLFilePath, | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         $sheetIndex, | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $sheetName, | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         $isSheetActive, | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $optionsManager, | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         $sharedStringsManager | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 33 |  |         $rowIterator = $this->createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 71 | 33 |  |         return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive); | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @param string $filePath Path of the XLSX file being read | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @param SharedStringsManager $sharedStringsManager Manages shared strings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @return RowIterator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 33 |  |     private function createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 33 |  |         $xmlReader = $this->createXMLReader(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 33 |  |         $xmlProcessor = $this->createXMLProcessor($xmlReader); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 33 |  |         $styleManager = $this->managerFactory->createStyleManager($filePath, $this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 33 |  |         $shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 33 |  |         $shouldUse1904Dates = $optionsManager->getOption(Options::SHOULD_USE_1904_DATES); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 33 |  |         $cellValueFormatter = $this->helperFactory->createCellValueFormatter( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             $sharedStringsManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 33 |  |             $styleManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 33 |  |             $shouldFormatDates, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 33 |  |             $shouldUse1904Dates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 33 |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 33 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 33 |  |         $shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 33 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return new RowIterator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             $filePath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             $sheetDataXMLFilePath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             $shouldPreserveEmptyRows, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             $xmlReader, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             $xmlProcessor, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 36 |  |             $cellValueFormatter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 36 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @return \ZipArchive | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     public function createZipArchive() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 41 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         return new \ZipArchive(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 | 41 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @return XMLReader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     public function createXMLReader() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 33 |  |         return new XMLReader(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 33 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * @param $xmlReader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * @return XMLProcessor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     public function createXMLProcessor($xmlReader) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         return new XMLProcessor($xmlReader); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 133 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 134 |  |  |  |