Add random DI improvements
Fixing things that were previously missed
This commit is contained in:
parent
b7e46740ce
commit
d5e4a67d65
@ -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,6 +2,7 @@
|
||||
|
||||
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;
|
||||
@ -55,4 +56,21 @@ class EntityFactory
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -61,7 +61,7 @@ class InternalFactory implements InternalFactoryInterface
|
||||
$stringsEscaper = $this->createStringsEscaper();
|
||||
$stringsHelper = $this->createStringHelper();
|
||||
|
||||
return new WorksheetManager($stringsEscaper, $stringsHelper);
|
||||
return new WorksheetManager($stringsEscaper, $stringsHelper, $this->entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,7 +101,7 @@ class InternalFactory implements InternalFactoryInterface
|
||||
*/
|
||||
private function createZipHelper()
|
||||
{
|
||||
return new ZipHelper();
|
||||
return new ZipHelper($this->entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()) {
|
||||
|
@ -72,7 +72,7 @@ class InternalFactory implements InternalFactoryInterface
|
||||
$stringsEscaper = $this->createStringsEscaper();
|
||||
$stringsHelper = $this->createStringHelper();
|
||||
|
||||
return new WorksheetManager($optionsManager, $styleManager, $sharedStringsManager, $stringsEscaper, $stringsHelper);
|
||||
return new WorksheetManager($optionsManager, $styleManager, $sharedStringsManager, $stringsEscaper, $stringsHelper, $this->entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,7 +123,7 @@ class InternalFactory implements InternalFactoryInterface
|
||||
*/
|
||||
private function createZipHelper()
|
||||
{
|
||||
return new ZipHelper();
|
||||
return new ZipHelper($this->entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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