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:
1 parent
b7e46740ce
commit
4ec3a21170
19 files changed
+317
-183
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
+8
-2
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user