Random DI improvements (#458)
* Add random DI improvements Fixing things that were previously missed * Split InternalFactory into Manager and Helper factories
This commit is contained in:
parent
b7e46740ce
commit
4ec3a21170
@ -5,6 +5,7 @@ namespace Box\Spout\Common\Creator;
|
||||
use Box\Spout\Common\Helper\EncodingHelper;
|
||||
use Box\Spout\Common\Helper\FileSystemHelper;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
|
||||
/**
|
||||
* Class HelperFactory
|
||||
@ -39,4 +40,12 @@ class HelperFactory
|
||||
{
|
||||
return new EncodingHelper($globalFunctionsHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StringHelper
|
||||
*/
|
||||
public function createStringHelper()
|
||||
{
|
||||
return new StringHelper();
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,12 @@ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EntityFactory $entityFactory
|
||||
* @return SettingsHelper
|
||||
*/
|
||||
public function createSettingsHelper()
|
||||
public function createSettingsHelper($entityFactory)
|
||||
{
|
||||
return new SettingsHelper();
|
||||
return new SettingsHelper($entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Box\Spout\Reader\ODS\Helper;
|
||||
|
||||
use Box\Spout\Reader\Exception\XMLProcessingException;
|
||||
use Box\Spout\Reader\ODS\Creator\EntityFactory;
|
||||
use Box\Spout\Reader\Wrapper\XMLReader;
|
||||
|
||||
/**
|
||||
@ -20,13 +21,24 @@ class SettingsHelper
|
||||
const XML_ATTRIBUTE_CONFIG_NAME = 'config:name';
|
||||
const XML_ATTRIBUTE_VALUE_ACTIVE_TABLE = 'ActiveTable';
|
||||
|
||||
/** @var EntityFactory Factory to create entities */
|
||||
private $entityFactory;
|
||||
|
||||
/**
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
*/
|
||||
public function __construct($entityFactory)
|
||||
{
|
||||
$this->entityFactory = $entityFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath Path of the file to be read
|
||||
* @return string|null Name of the sheet that was defined as active or NULL if none found
|
||||
*/
|
||||
public function getActiveSheetName($filePath)
|
||||
{
|
||||
$xmlReader = new XMLReader();
|
||||
$xmlReader = $this->entityFactory->createXMLReader();
|
||||
if ($xmlReader->openFileInZip($filePath, self::SETTINGS_XML_FILE_PATH) === false) {
|
||||
return null;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class SheetIterator implements IteratorInterface
|
||||
|
||||
$this->escaper = $helperFactory->createStringsEscaper();
|
||||
|
||||
$settingsHelper = $helperFactory->createSettingsHelper();
|
||||
$settingsHelper = $helperFactory->createSettingsHelper($entityFactory);
|
||||
$this->activeSheetName = $settingsHelper->getActiveSheetName($filePath);
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,11 @@
|
||||
|
||||
namespace Box\Spout\Writer\Common\Creator;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Cell;
|
||||
use Box\Spout\Writer\Common\Entity\Sheet;
|
||||
use Box\Spout\Writer\Common\Entity\Workbook;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
|
||||
/**
|
||||
* Class EntityFactory
|
||||
@ -14,19 +16,6 @@ use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
*/
|
||||
class EntityFactory
|
||||
{
|
||||
/** @var ManagerFactory */
|
||||
private $managerFactory;
|
||||
|
||||
/**
|
||||
* EntityFactory constructor.
|
||||
*
|
||||
* @param ManagerFactory $managerFactory
|
||||
*/
|
||||
public function __construct(ManagerFactory $managerFactory)
|
||||
{
|
||||
$this->managerFactory = $managerFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Workbook
|
||||
*/
|
||||
@ -48,11 +37,28 @@ class EntityFactory
|
||||
/**
|
||||
* @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
|
||||
* @param string $associatedWorkbookId ID of the sheet's associated workbook
|
||||
* @param SheetManager $sheetManager To manage sheets
|
||||
* @return Sheet
|
||||
*/
|
||||
public function createSheet($sheetIndex, $associatedWorkbookId)
|
||||
public function createSheet($sheetIndex, $associatedWorkbookId, $sheetManager)
|
||||
{
|
||||
$sheetManager = $this->managerFactory->createSheetManager();
|
||||
return new Sheet($sheetIndex, $associatedWorkbookId, $sheetManager);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $cellValue
|
||||
* @return Cell
|
||||
*/
|
||||
public function createCell($cellValue)
|
||||
{
|
||||
return new Cell($cellValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \ZipArchive
|
||||
*/
|
||||
public function createZipArchive()
|
||||
{
|
||||
return new \ZipArchive();
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Creator;
|
||||
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
|
||||
/**
|
||||
* Class ManagerFactory
|
||||
* Factory to create managers
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Creator
|
||||
*/
|
||||
class ManagerFactory
|
||||
{
|
||||
/**
|
||||
* @return SheetManager
|
||||
*/
|
||||
public function createSheetManager()
|
||||
{
|
||||
$stringHelper = new StringHelper();
|
||||
return new SheetManager($stringHelper);
|
||||
}
|
||||
}
|
@ -3,18 +3,24 @@
|
||||
namespace Box\Spout\Writer\Common\Creator;
|
||||
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface;
|
||||
|
||||
/**
|
||||
* Interface InternalFactoryInterface
|
||||
* Interface ManagerFactoryInterface
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Creator
|
||||
*/
|
||||
interface InternalFactoryInterface
|
||||
interface ManagerFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @return WorkbookManagerInterface
|
||||
*/
|
||||
public function createWorkbookManager(OptionsManagerInterface $optionsManager);
|
||||
|
||||
/**
|
||||
* @return SheetManager
|
||||
*/
|
||||
public function createSheetManager();
|
||||
}
|
@ -29,7 +29,7 @@ class Sheet
|
||||
/**
|
||||
* @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
|
||||
* @param string $associatedWorkbookId ID of the sheet's associated workbook
|
||||
* @param SheetManager $sheetManager
|
||||
* @param SheetManager $sheetManager To manage sheets
|
||||
*/
|
||||
public function __construct($sheetIndex, $associatedWorkbookId, SheetManager $sheetManager)
|
||||
{
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace Box\Spout\Writer\Common\Helper;
|
||||
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
|
||||
/**
|
||||
* Class ZipHelper
|
||||
* This class provides helper functions to create zip files
|
||||
@ -16,6 +18,17 @@ class ZipHelper
|
||||
const EXISTING_FILES_SKIP = 'skip';
|
||||
const EXISTING_FILES_OVERWRITE = 'overwrite';
|
||||
|
||||
/** @var EntityFactory Factory to create entities */
|
||||
private $entityFactory;
|
||||
|
||||
/**
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
*/
|
||||
public function __construct($entityFactory)
|
||||
{
|
||||
$this->entityFactory = $entityFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new ZipArchive instance pointing at the given path.
|
||||
*
|
||||
@ -24,7 +37,7 @@ class ZipHelper
|
||||
*/
|
||||
public function createZip($tmpFolderPath)
|
||||
{
|
||||
$zip = new \ZipArchive();
|
||||
$zip = $this->entityFactory->createZipArchive();
|
||||
$zipFilePath = $tmpFolderPath . self::ZIP_EXTENSION;
|
||||
|
||||
$zip->open($zipFilePath, \ZipArchive::CREATE|\ZipArchive::OVERWRITE);
|
||||
|
@ -4,6 +4,7 @@ namespace Box\Spout\Writer\Common\Manager;
|
||||
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface;
|
||||
@ -41,6 +42,9 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
/** @var EntityFactory Factory to create entities */
|
||||
protected $entityFactory;
|
||||
|
||||
/** @var ManagerFactoryInterface $managerFactory Factory to create managers */
|
||||
protected $managerFactory;
|
||||
|
||||
/** @var Worksheet The worksheet where data will be written to */
|
||||
protected $currentWorksheet;
|
||||
|
||||
@ -52,6 +56,7 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
* @param StyleManagerInterface $styleManager
|
||||
* @param FileSystemWithRootFolderHelperInterface $fileSystemHelper
|
||||
* @param EntityFactory $entityFactory
|
||||
* @param ManagerFactoryInterface $managerFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Workbook $workbook,
|
||||
@ -59,7 +64,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
WorksheetManagerInterface $worksheetManager,
|
||||
StyleManagerInterface $styleManager,
|
||||
FileSystemWithRootFolderHelperInterface $fileSystemHelper,
|
||||
EntityFactory $entityFactory)
|
||||
EntityFactory $entityFactory,
|
||||
ManagerFactoryInterface $managerFactory)
|
||||
{
|
||||
$this->workbook = $workbook;
|
||||
$this->optionManager = $optionsManager;
|
||||
@ -67,6 +73,7 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
$this->styleManager = $styleManager;
|
||||
$this->fileSystemHelper = $fileSystemHelper;
|
||||
$this->entityFactory = $entityFactory;
|
||||
$this->managerFactory = $managerFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,7 +121,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
$worksheets = $this->getWorksheets();
|
||||
|
||||
$newSheetIndex = count($worksheets);
|
||||
$sheet = $this->entityFactory->createSheet($newSheetIndex, $this->workbook->getInternalId());
|
||||
$sheetManager = $this->managerFactory->createSheetManager();
|
||||
$sheet = $this->entityFactory->createSheet($newSheetIndex, $this->workbook->getInternalId(), $sheetManager);
|
||||
|
||||
$worksheetFilePath = $this->getWorksheetFilePath($sheet);
|
||||
$worksheet = $this->entityFactory->createWorksheet($worksheetFilePath, $sheet);
|
||||
|
58
src/Spout/Writer/ODS/Creator/HelperFactory.php
Normal file
58
src/Spout/Writer/ODS/Creator/HelperFactory.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\ODS\Creator;
|
||||
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Helper\ZipHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\ODS\Helper\FileSystemHelper;
|
||||
use Box\Spout\Common\Helper\Escaper;
|
||||
|
||||
/**
|
||||
* Class HelperFactory
|
||||
* Factory for helpers needed by the ODS Writer
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Creator
|
||||
*/
|
||||
class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
|
||||
{
|
||||
/**
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param EntityFactory $entityFactory
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
public function createSpecificFileSystemHelper(OptionsManagerInterface $optionsManager, EntityFactory $entityFactory)
|
||||
{
|
||||
$tempFolder = $optionsManager->getOption(Options::TEMP_FOLDER);
|
||||
$zipHelper = $this->createZipHelper($entityFactory);
|
||||
|
||||
return new FileSystemHelper($tempFolder, $zipHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entityFactory
|
||||
* @return ZipHelper
|
||||
*/
|
||||
private function createZipHelper($entityFactory)
|
||||
{
|
||||
return new ZipHelper($entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Escaper\ODS
|
||||
*/
|
||||
public function createStringsEscaper()
|
||||
{
|
||||
return new Escaper\ODS();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StringHelper
|
||||
*/
|
||||
public function createStringHelper()
|
||||
{
|
||||
return new StringHelper();
|
||||
}
|
||||
}
|
@ -2,38 +2,38 @@
|
||||
|
||||
namespace Box\Spout\Writer\ODS\Creator;
|
||||
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Helper\ZipHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Creator\InternalFactoryInterface;
|
||||
use Box\Spout\Writer\ODS\Helper\FileSystemHelper;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
|
||||
use Box\Spout\Writer\ODS\Manager\Style\StyleRegistry;
|
||||
use Box\Spout\Writer\ODS\Manager\WorkbookManager;
|
||||
use Box\Spout\Writer\ODS\Manager\WorksheetManager;
|
||||
use Box\Spout\Common\Helper\Escaper;
|
||||
|
||||
/**
|
||||
* Class InternalFactory
|
||||
* Factory for all useful types of objects needed by the ODS Writer
|
||||
* Class ManagerFactory
|
||||
* Factory for managers needed by the ODS Writer
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Creator
|
||||
*/
|
||||
class InternalFactory implements InternalFactoryInterface
|
||||
class ManagerFactory implements ManagerFactoryInterface
|
||||
{
|
||||
/** @var EntityFactory */
|
||||
private $entityFactory;
|
||||
protected $entityFactory;
|
||||
|
||||
/** @var HelperFactory $helperFactory */
|
||||
protected $helperFactory;
|
||||
|
||||
/**
|
||||
* InternalFactory constructor.
|
||||
*
|
||||
* @param EntityFactory $entityFactory
|
||||
* @param HelperFactory $helperFactory
|
||||
*/
|
||||
public function __construct(EntityFactory $entityFactory)
|
||||
public function __construct(EntityFactory $entityFactory, HelperFactory $helperFactory)
|
||||
{
|
||||
$this->entityFactory = $entityFactory;
|
||||
$this->helperFactory = $helperFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,13 +44,21 @@ class InternalFactory implements InternalFactoryInterface
|
||||
{
|
||||
$workbook = $this->entityFactory->createWorkbook();
|
||||
|
||||
$fileSystemHelper = $this->createFileSystemHelper($optionsManager);
|
||||
$fileSystemHelper = $this->helperFactory->createSpecificFileSystemHelper($optionsManager, $this->entityFactory);
|
||||
$fileSystemHelper->createBaseFilesAndFolders();
|
||||
|
||||
$styleManager = $this->createStyleManager($optionsManager);
|
||||
$worksheetManager = $this->createWorksheetManager();
|
||||
|
||||
return new WorkbookManager($workbook, $optionsManager, $worksheetManager, $styleManager, $fileSystemHelper, $this->entityFactory);
|
||||
return new WorkbookManager(
|
||||
$workbook,
|
||||
$optionsManager,
|
||||
$worksheetManager,
|
||||
$styleManager,
|
||||
$fileSystemHelper,
|
||||
$this->entityFactory,
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,10 +66,19 @@ class InternalFactory implements InternalFactoryInterface
|
||||
*/
|
||||
private function createWorksheetManager()
|
||||
{
|
||||
$stringsEscaper = $this->createStringsEscaper();
|
||||
$stringsHelper = $this->createStringHelper();
|
||||
$stringsEscaper = $this->helperFactory->createStringsEscaper();
|
||||
$stringsHelper = $this->helperFactory->createStringHelper();
|
||||
|
||||
return new WorksheetManager($stringsEscaper, $stringsHelper);
|
||||
return new WorksheetManager($stringsEscaper, $stringsHelper, $this->entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SheetManager
|
||||
*/
|
||||
public function createSheetManager()
|
||||
{
|
||||
$stringHelper = $this->helperFactory->createStringHelper();
|
||||
return new SheetManager($stringHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,40 +100,4 @@ class InternalFactory implements InternalFactoryInterface
|
||||
$defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE);
|
||||
return new StyleRegistry($defaultRowStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
public function createFileSystemHelper(OptionsManagerInterface $optionsManager)
|
||||
{
|
||||
$tempFolder = $optionsManager->getOption(Options::TEMP_FOLDER);
|
||||
$zipHelper = $this->createZipHelper();
|
||||
|
||||
return new FileSystemHelper($tempFolder, $zipHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ZipHelper
|
||||
*/
|
||||
private function createZipHelper()
|
||||
{
|
||||
return new ZipHelper();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Escaper\ODS
|
||||
*/
|
||||
private function createStringsEscaper()
|
||||
{
|
||||
return new Escaper\ODS();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StringHelper
|
||||
*/
|
||||
private function createStringHelper()
|
||||
{
|
||||
return new StringHelper();
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ namespace Box\Spout\Writer\ODS\Manager;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Entity\Cell;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface;
|
||||
@ -25,18 +26,24 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
/** @var StringHelper String helper */
|
||||
private $stringHelper;
|
||||
|
||||
/** @var EntityFactory Factory to create entities */
|
||||
private $entityFactory;
|
||||
|
||||
/**
|
||||
* WorksheetManager constructor.
|
||||
*
|
||||
* @param \Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper
|
||||
* @param StringHelper $stringHelper
|
||||
* @param EntityFactory $entityFactory
|
||||
*/
|
||||
public function __construct(
|
||||
\Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper,
|
||||
StringHelper $stringHelper)
|
||||
StringHelper $stringHelper,
|
||||
EntityFactory $entityFactory)
|
||||
{
|
||||
$this->stringsEscaper = $stringsEscaper;
|
||||
$this->stringHelper = $stringHelper;
|
||||
$this->entityFactory = $entityFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,7 +167,7 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
if ($cellValue instanceof Cell) {
|
||||
$cell = $cellValue;
|
||||
} else {
|
||||
$cell = new Cell($cellValue);
|
||||
$cell = $this->entityFactory->createCell($cellValue);
|
||||
}
|
||||
|
||||
if ($cell->isString()) {
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace Box\Spout\Writer;
|
||||
|
||||
use Box\Spout\Common\Creator\HelperFactory;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Exception\SpoutException;
|
||||
use Box\Spout\Common\Helper\FileSystemHelper;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
@ -34,6 +34,9 @@ abstract class WriterAbstract implements WriterInterface
|
||||
/** @var GlobalFunctionsHelper Helper to work with global functions */
|
||||
protected $globalFunctionsHelper;
|
||||
|
||||
/** @var HelperFactory $helperFactory */
|
||||
protected $helperFactory;
|
||||
|
||||
/** @var OptionsManagerInterface Writer options manager */
|
||||
protected $optionsManager;
|
||||
|
||||
@ -50,15 +53,18 @@ abstract class WriterAbstract implements WriterInterface
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param StyleMerger $styleMerger
|
||||
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @param HelperFactory $helperFactory
|
||||
*/
|
||||
public function __construct(
|
||||
OptionsManagerInterface $optionsManager,
|
||||
StyleMerger $styleMerger,
|
||||
GlobalFunctionsHelper $globalFunctionsHelper)
|
||||
GlobalFunctionsHelper $globalFunctionsHelper,
|
||||
HelperFactory $helperFactory)
|
||||
{
|
||||
$this->optionsManager = $optionsManager;
|
||||
$this->styleMerger = $styleMerger;
|
||||
$this->globalFunctionsHelper = $globalFunctionsHelper;
|
||||
$this->helperFactory = $helperFactory;
|
||||
|
||||
$this->resetRowStyleToDefault();
|
||||
}
|
||||
@ -372,7 +378,7 @@ abstract class WriterAbstract implements WriterInterface
|
||||
// remove output file if it was created
|
||||
if ($this->globalFunctionsHelper->file_exists($this->outputFilePath)) {
|
||||
$outputFolderPath = dirname($this->outputFilePath);
|
||||
$fileSystemHelper = new FileSystemHelper($outputFolderPath);
|
||||
$fileSystemHelper = $this->helperFactory->createFileSystemHelper($outputFolderPath);
|
||||
$fileSystemHelper->deleteFile($this->outputFilePath);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
namespace Box\Spout\Writer;
|
||||
|
||||
use Box\Spout\Common\Creator\HelperFactory;
|
||||
use Box\Spout\Common\Exception\UnsupportedTypeException;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Creator\ManagerFactory;
|
||||
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||
|
||||
@ -47,7 +47,9 @@ class WriterFactory
|
||||
$styleMerger = new StyleMerger();
|
||||
$globalFunctionsHelper = new GlobalFunctionsHelper();
|
||||
|
||||
return new CSV\Writer($optionsManager, $styleMerger, $globalFunctionsHelper);
|
||||
$helperFactory = new HelperFactory();
|
||||
|
||||
return new CSV\Writer($optionsManager, $styleMerger, $globalFunctionsHelper, $helperFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,10 +62,10 @@ class WriterFactory
|
||||
$styleMerger = new StyleMerger();
|
||||
$globalFunctionsHelper = new GlobalFunctionsHelper();
|
||||
|
||||
$entityFactory = new EntityFactory(new ManagerFactory());
|
||||
$internalFactory = new XLSX\Creator\InternalFactory($entityFactory);
|
||||
$helperFactory = new XLSX\Creator\HelperFactory();
|
||||
$managerFactory = new XLSX\Creator\ManagerFactory(new EntityFactory(), $helperFactory);
|
||||
|
||||
return new XLSX\Writer($optionsManager, $styleMerger, $globalFunctionsHelper, $internalFactory);
|
||||
return new XLSX\Writer($optionsManager, $styleMerger, $globalFunctionsHelper, $helperFactory, $managerFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,9 +78,9 @@ class WriterFactory
|
||||
$styleMerger = new StyleMerger();
|
||||
$globalFunctionsHelper = new GlobalFunctionsHelper();
|
||||
|
||||
$entityFactory = new EntityFactory(new ManagerFactory());
|
||||
$internalFactory = new ODS\Creator\InternalFactory($entityFactory);
|
||||
$helperFactory = new ODS\Creator\HelperFactory();
|
||||
$managerFactory = new ODS\Creator\ManagerFactory(new EntityFactory(), $helperFactory);
|
||||
|
||||
return new ODS\Writer($optionsManager, $styleMerger, $globalFunctionsHelper, $internalFactory);
|
||||
return new ODS\Writer($optionsManager, $styleMerger, $globalFunctionsHelper, $helperFactory, $managerFactory);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Box\Spout\Writer;
|
||||
|
||||
use Box\Spout\Common\Creator\HelperFactory;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Writer\Common\Entity\Sheet;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
@ -9,8 +10,9 @@ use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||
use Box\Spout\Writer\Exception\SheetNotFoundException;
|
||||
use Box\Spout\Writer\Exception\WriterAlreadyOpenedException;
|
||||
use Box\Spout\Writer\Exception\WriterNotOpenedException;
|
||||
use Box\Spout\Writer\Common\Creator\InternalFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface;
|
||||
|
||||
/**
|
||||
@ -21,9 +23,8 @@ use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface;
|
||||
*/
|
||||
abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
{
|
||||
|
||||
/** @var InternalFactoryInterface */
|
||||
private $internalFactory;
|
||||
/** @var ManagerFactoryInterface */
|
||||
private $managerFactory;
|
||||
|
||||
/** @var WorkbookManagerInterface */
|
||||
private $workbookManager;
|
||||
@ -32,16 +33,18 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param StyleMerger $styleMerger
|
||||
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @param InternalFactoryInterface $internalFactory
|
||||
* @param HelperFactory $helperFactory
|
||||
* @param ManagerFactoryInterface $managerFactory
|
||||
*/
|
||||
public function __construct(
|
||||
OptionsManagerInterface $optionsManager,
|
||||
StyleMerger $styleMerger,
|
||||
GlobalFunctionsHelper $globalFunctionsHelper,
|
||||
InternalFactoryInterface $internalFactory)
|
||||
HelperFactory $helperFactory,
|
||||
ManagerFactoryInterface $managerFactory)
|
||||
{
|
||||
parent::__construct($optionsManager, $styleMerger, $globalFunctionsHelper);
|
||||
$this->internalFactory = $internalFactory;
|
||||
parent::__construct($optionsManager, $styleMerger, $globalFunctionsHelper, $helperFactory);
|
||||
$this->managerFactory = $managerFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,7 +73,7 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
protected function openWriter()
|
||||
{
|
||||
if (!$this->workbookManager) {
|
||||
$this->workbookManager = $this->internalFactory->createWorkbookManager($this->optionsManager);
|
||||
$this->workbookManager = $this->managerFactory->createWorkbookManager($this->optionsManager);
|
||||
$this->workbookManager->addNewSheetAndMakeItCurrent();
|
||||
}
|
||||
}
|
||||
|
59
src/Spout/Writer/XLSX/Creator/HelperFactory.php
Normal file
59
src/Spout/Writer/XLSX/Creator/HelperFactory.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\XLSX\Creator;
|
||||
|
||||
use Box\Spout\Common\Helper\Escaper;
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Helper\ZipHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\XLSX\Helper\FileSystemHelper;
|
||||
|
||||
/**
|
||||
* Class HelperFactory
|
||||
* Factory for helpers needed by the XLSX Writer
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Creator
|
||||
*/
|
||||
class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
|
||||
{
|
||||
/**
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param EntityFactory $entityFactory
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
public function createSpecificFileSystemHelper(OptionsManagerInterface $optionsManager, EntityFactory $entityFactory)
|
||||
{
|
||||
$tempFolder = $optionsManager->getOption(Options::TEMP_FOLDER);
|
||||
$zipHelper = $this->createZipHelper($entityFactory);
|
||||
$escaper = $this->createStringsEscaper();
|
||||
|
||||
return new FileSystemHelper($tempFolder, $zipHelper, $escaper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EntityFactory $entityFactory
|
||||
* @return ZipHelper
|
||||
*/
|
||||
private function createZipHelper(EntityFactory $entityFactory)
|
||||
{
|
||||
return new ZipHelper($entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Escaper\XLSX
|
||||
*/
|
||||
public function createStringsEscaper()
|
||||
{
|
||||
return new Escaper\XLSX();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StringHelper
|
||||
*/
|
||||
public function createStringHelper()
|
||||
{
|
||||
return new StringHelper();
|
||||
}
|
||||
}
|
@ -2,14 +2,11 @@
|
||||
|
||||
namespace Box\Spout\Writer\XLSX\Creator;
|
||||
|
||||
use Box\Spout\Common\Helper\Escaper;
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Creator\InternalFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Helper\ZipHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\XLSX\Helper\FileSystemHelper;
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
use Box\Spout\Writer\XLSX\Manager\SharedStringsManager;
|
||||
use Box\Spout\Writer\XLSX\Manager\Style\StyleManager;
|
||||
use Box\Spout\Writer\XLSX\Manager\Style\StyleRegistry;
|
||||
@ -17,24 +14,27 @@ use Box\Spout\Writer\XLSX\Manager\WorkbookManager;
|
||||
use Box\Spout\Writer\XLSX\Manager\WorksheetManager;
|
||||
|
||||
/**
|
||||
* Class InternalFactory
|
||||
* Factory for all useful types of objects needed by the XLSX Writer
|
||||
* Class ManagerFactory
|
||||
* Factory for managers needed by the XLSX Writer
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Creator
|
||||
*/
|
||||
class InternalFactory implements InternalFactoryInterface
|
||||
class ManagerFactory implements ManagerFactoryInterface
|
||||
{
|
||||
/** @var EntityFactory */
|
||||
private $entityFactory;
|
||||
protected $entityFactory;
|
||||
|
||||
/** @var HelperFactory $helperFactory */
|
||||
protected $helperFactory;
|
||||
|
||||
/**
|
||||
* InternalFactory constructor.
|
||||
*
|
||||
* @param EntityFactory $entityFactory
|
||||
* @param HelperFactory $helperFactory
|
||||
*/
|
||||
public function __construct(EntityFactory $entityFactory)
|
||||
public function __construct(EntityFactory $entityFactory, HelperFactory $helperFactory)
|
||||
{
|
||||
$this->entityFactory = $entityFactory;
|
||||
$this->helperFactory = $helperFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +45,7 @@ class InternalFactory implements InternalFactoryInterface
|
||||
{
|
||||
$workbook = $this->entityFactory->createWorkbook();
|
||||
|
||||
$fileSystemHelper = $this->createFileSystemHelper($optionsManager);
|
||||
$fileSystemHelper = $this->helperFactory->createSpecificFileSystemHelper($optionsManager, $this->entityFactory);
|
||||
$fileSystemHelper->createBaseFilesAndFolders();
|
||||
|
||||
$xlFolder = $fileSystemHelper->getXlFolder();
|
||||
@ -54,7 +54,15 @@ class InternalFactory implements InternalFactoryInterface
|
||||
$styleManager = $this->createStyleManager($optionsManager);
|
||||
$worksheetManager = $this->createWorksheetManager($optionsManager, $styleManager, $sharedStringsManager);
|
||||
|
||||
return new WorkbookManager($workbook, $optionsManager, $worksheetManager, $styleManager, $fileSystemHelper, $this->entityFactory);
|
||||
return new WorkbookManager(
|
||||
$workbook,
|
||||
$optionsManager,
|
||||
$worksheetManager,
|
||||
$styleManager,
|
||||
$fileSystemHelper,
|
||||
$this->entityFactory,
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,10 +77,19 @@ class InternalFactory implements InternalFactoryInterface
|
||||
SharedStringsManager $sharedStringsManager
|
||||
)
|
||||
{
|
||||
$stringsEscaper = $this->createStringsEscaper();
|
||||
$stringsHelper = $this->createStringHelper();
|
||||
$stringsEscaper = $this->helperFactory->createStringsEscaper();
|
||||
$stringsHelper = $this->helperFactory->createStringHelper();
|
||||
|
||||
return new WorksheetManager($optionsManager, $styleManager, $sharedStringsManager, $stringsEscaper, $stringsHelper);
|
||||
return new WorksheetManager($optionsManager, $styleManager, $sharedStringsManager, $stringsEscaper, $stringsHelper, $this->entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SheetManager
|
||||
*/
|
||||
public function createSheetManager()
|
||||
{
|
||||
$stringHelper = $this->helperFactory->createStringHelper();
|
||||
return new SheetManager($stringHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,44 +118,7 @@ class InternalFactory implements InternalFactoryInterface
|
||||
*/
|
||||
private function createSharedStringsManager($xlFolder)
|
||||
{
|
||||
$stringEscaper = $this->createStringsEscaper();
|
||||
$stringEscaper = $this->helperFactory->createStringsEscaper();
|
||||
return new SharedStringsManager($xlFolder, $stringEscaper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createFileSystemHelper(OptionsManagerInterface $optionsManager)
|
||||
{
|
||||
$tempFolder = $optionsManager->getOption(Options::TEMP_FOLDER);
|
||||
$zipHelper = $this->createZipHelper();
|
||||
$escaper = $this->createStringsEscaper();
|
||||
|
||||
return new FileSystemHelper($tempFolder, $zipHelper, $escaper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ZipHelper
|
||||
*/
|
||||
private function createZipHelper()
|
||||
{
|
||||
return new ZipHelper();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Escaper\XLSX
|
||||
*/
|
||||
private function createStringsEscaper()
|
||||
{
|
||||
return new Escaper\XLSX();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StringHelper
|
||||
*/
|
||||
private function createStringHelper()
|
||||
{
|
||||
return new StringHelper();
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ namespace Box\Spout\Writer\XLSX\Manager;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Helper\CellHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
@ -50,6 +51,9 @@ EOD;
|
||||
/** @var StringHelper String helper */
|
||||
private $stringHelper;
|
||||
|
||||
/** @var EntityFactory Factory to create entities */
|
||||
private $entityFactory;
|
||||
|
||||
/**
|
||||
* WorksheetManager constructor.
|
||||
*
|
||||
@ -58,19 +62,22 @@ EOD;
|
||||
* @param SharedStringsManager $sharedStringsManager
|
||||
* @param \Box\Spout\Common\Helper\Escaper\XLSX $stringsEscaper
|
||||
* @param StringHelper $stringHelper
|
||||
* @param EntityFactory $entityFactory
|
||||
*/
|
||||
public function __construct(
|
||||
OptionsManagerInterface $optionsManager,
|
||||
StyleManager $styleManager,
|
||||
SharedStringsManager $sharedStringsManager,
|
||||
\Box\Spout\Common\Helper\Escaper\XLSX $stringsEscaper,
|
||||
StringHelper $stringHelper)
|
||||
StringHelper $stringHelper,
|
||||
EntityFactory $entityFactory)
|
||||
{
|
||||
$this->shouldUseInlineStrings = $optionsManager->getOption(Options::SHOULD_USE_INLINE_STRINGS);
|
||||
$this->styleManager = $styleManager;
|
||||
$this->sharedStringsManager = $sharedStringsManager;
|
||||
$this->stringsEscaper = $stringsEscaper;
|
||||
$this->stringHelper = $stringHelper;
|
||||
$this->entityFactory = $entityFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,7 +207,7 @@ EOD;
|
||||
if ($cellValue instanceof Cell) {
|
||||
$cell = $cellValue;
|
||||
} else {
|
||||
$cell = new Cell($cellValue);
|
||||
$cell = $this->entityFactory->createCell($cellValue);
|
||||
}
|
||||
|
||||
if ($cell->isString()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user