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
|
* @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;
|
namespace Box\Spout\Reader\ODS\Helper;
|
||||||
|
|
||||||
use Box\Spout\Reader\Exception\XMLProcessingException;
|
use Box\Spout\Reader\Exception\XMLProcessingException;
|
||||||
|
use Box\Spout\Reader\ODS\Creator\EntityFactory;
|
||||||
use Box\Spout\Reader\Wrapper\XMLReader;
|
use Box\Spout\Reader\Wrapper\XMLReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,13 +21,24 @@ class SettingsHelper
|
|||||||
const XML_ATTRIBUTE_CONFIG_NAME = 'config:name';
|
const XML_ATTRIBUTE_CONFIG_NAME = 'config:name';
|
||||||
const XML_ATTRIBUTE_VALUE_ACTIVE_TABLE = 'ActiveTable';
|
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
|
* @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
|
* @return string|null Name of the sheet that was defined as active or NULL if none found
|
||||||
*/
|
*/
|
||||||
public function getActiveSheetName($filePath)
|
public function getActiveSheetName($filePath)
|
||||||
{
|
{
|
||||||
$xmlReader = new XMLReader();
|
$xmlReader = $this->entityFactory->createXMLReader();
|
||||||
if ($xmlReader->openFileInZip($filePath, self::SETTINGS_XML_FILE_PATH) === false) {
|
if ($xmlReader->openFileInZip($filePath, self::SETTINGS_XML_FILE_PATH) === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ class SheetIterator implements IteratorInterface
|
|||||||
|
|
||||||
$this->escaper = $helperFactory->createStringsEscaper();
|
$this->escaper = $helperFactory->createStringsEscaper();
|
||||||
|
|
||||||
$settingsHelper = $helperFactory->createSettingsHelper();
|
$settingsHelper = $helperFactory->createSettingsHelper($entityFactory);
|
||||||
$this->activeSheetName = $settingsHelper->getActiveSheetName($filePath);
|
$this->activeSheetName = $settingsHelper->getActiveSheetName($filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Box\Spout\Writer\Common\Creator;
|
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\Sheet;
|
||||||
use Box\Spout\Writer\Common\Entity\Workbook;
|
use Box\Spout\Writer\Common\Entity\Workbook;
|
||||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||||
@ -55,4 +56,21 @@ class EntityFactory
|
|||||||
$sheetManager = $this->managerFactory->createSheetManager();
|
$sheetManager = $this->managerFactory->createSheetManager();
|
||||||
return new Sheet($sheetIndex, $associatedWorkbookId, $sheetManager);
|
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;
|
namespace Box\Spout\Writer\Common\Helper;
|
||||||
|
|
||||||
|
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ZipHelper
|
* Class ZipHelper
|
||||||
* This class provides helper functions to create zip files
|
* This class provides helper functions to create zip files
|
||||||
@ -16,6 +18,17 @@ class ZipHelper
|
|||||||
const EXISTING_FILES_SKIP = 'skip';
|
const EXISTING_FILES_SKIP = 'skip';
|
||||||
const EXISTING_FILES_OVERWRITE = 'overwrite';
|
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.
|
* Returns a new ZipArchive instance pointing at the given path.
|
||||||
*
|
*
|
||||||
@ -24,7 +37,7 @@ class ZipHelper
|
|||||||
*/
|
*/
|
||||||
public function createZip($tmpFolderPath)
|
public function createZip($tmpFolderPath)
|
||||||
{
|
{
|
||||||
$zip = new \ZipArchive();
|
$zip = $this->entityFactory->createZipArchive();
|
||||||
$zipFilePath = $tmpFolderPath . self::ZIP_EXTENSION;
|
$zipFilePath = $tmpFolderPath . self::ZIP_EXTENSION;
|
||||||
|
|
||||||
$zip->open($zipFilePath, \ZipArchive::CREATE|\ZipArchive::OVERWRITE);
|
$zip->open($zipFilePath, \ZipArchive::CREATE|\ZipArchive::OVERWRITE);
|
||||||
|
@ -61,7 +61,7 @@ class InternalFactory implements InternalFactoryInterface
|
|||||||
$stringsEscaper = $this->createStringsEscaper();
|
$stringsEscaper = $this->createStringsEscaper();
|
||||||
$stringsHelper = $this->createStringHelper();
|
$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()
|
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\InvalidArgumentException;
|
||||||
use Box\Spout\Common\Exception\IOException;
|
use Box\Spout\Common\Exception\IOException;
|
||||||
use Box\Spout\Common\Helper\StringHelper;
|
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\Cell;
|
||||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||||
use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface;
|
use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface;
|
||||||
@ -25,18 +26,24 @@ class WorksheetManager implements WorksheetManagerInterface
|
|||||||
/** @var StringHelper String helper */
|
/** @var StringHelper String helper */
|
||||||
private $stringHelper;
|
private $stringHelper;
|
||||||
|
|
||||||
|
/** @var EntityFactory Factory to create entities */
|
||||||
|
private $entityFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WorksheetManager constructor.
|
* WorksheetManager constructor.
|
||||||
*
|
*
|
||||||
* @param \Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper
|
* @param \Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper
|
||||||
* @param StringHelper $stringHelper
|
* @param StringHelper $stringHelper
|
||||||
|
* @param EntityFactory $entityFactory
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper,
|
\Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper,
|
||||||
StringHelper $stringHelper)
|
StringHelper $stringHelper,
|
||||||
|
EntityFactory $entityFactory)
|
||||||
{
|
{
|
||||||
$this->stringsEscaper = $stringsEscaper;
|
$this->stringsEscaper = $stringsEscaper;
|
||||||
$this->stringHelper = $stringHelper;
|
$this->stringHelper = $stringHelper;
|
||||||
|
$this->entityFactory = $entityFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,7 +167,7 @@ class WorksheetManager implements WorksheetManagerInterface
|
|||||||
if ($cellValue instanceof Cell) {
|
if ($cellValue instanceof Cell) {
|
||||||
$cell = $cellValue;
|
$cell = $cellValue;
|
||||||
} else {
|
} else {
|
||||||
$cell = new Cell($cellValue);
|
$cell = $this->entityFactory->createCell($cellValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cell->isString()) {
|
if ($cell->isString()) {
|
||||||
|
@ -72,7 +72,7 @@ class InternalFactory implements InternalFactoryInterface
|
|||||||
$stringsEscaper = $this->createStringsEscaper();
|
$stringsEscaper = $this->createStringsEscaper();
|
||||||
$stringsHelper = $this->createStringHelper();
|
$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()
|
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\InvalidArgumentException;
|
||||||
use Box\Spout\Common\Exception\IOException;
|
use Box\Spout\Common\Exception\IOException;
|
||||||
use Box\Spout\Common\Helper\StringHelper;
|
use Box\Spout\Common\Helper\StringHelper;
|
||||||
|
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||||
use Box\Spout\Writer\Common\Helper\CellHelper;
|
use Box\Spout\Writer\Common\Helper\CellHelper;
|
||||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||||
use Box\Spout\Writer\Common\Entity\Options;
|
use Box\Spout\Writer\Common\Entity\Options;
|
||||||
@ -50,6 +51,9 @@ EOD;
|
|||||||
/** @var StringHelper String helper */
|
/** @var StringHelper String helper */
|
||||||
private $stringHelper;
|
private $stringHelper;
|
||||||
|
|
||||||
|
/** @var EntityFactory Factory to create entities */
|
||||||
|
private $entityFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WorksheetManager constructor.
|
* WorksheetManager constructor.
|
||||||
*
|
*
|
||||||
@ -58,19 +62,22 @@ EOD;
|
|||||||
* @param SharedStringsManager $sharedStringsManager
|
* @param SharedStringsManager $sharedStringsManager
|
||||||
* @param \Box\Spout\Common\Helper\Escaper\XLSX $stringsEscaper
|
* @param \Box\Spout\Common\Helper\Escaper\XLSX $stringsEscaper
|
||||||
* @param StringHelper $stringHelper
|
* @param StringHelper $stringHelper
|
||||||
|
* @param EntityFactory $entityFactory
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
OptionsManagerInterface $optionsManager,
|
OptionsManagerInterface $optionsManager,
|
||||||
StyleManager $styleManager,
|
StyleManager $styleManager,
|
||||||
SharedStringsManager $sharedStringsManager,
|
SharedStringsManager $sharedStringsManager,
|
||||||
\Box\Spout\Common\Helper\Escaper\XLSX $stringsEscaper,
|
\Box\Spout\Common\Helper\Escaper\XLSX $stringsEscaper,
|
||||||
StringHelper $stringHelper)
|
StringHelper $stringHelper,
|
||||||
|
EntityFactory $entityFactory)
|
||||||
{
|
{
|
||||||
$this->shouldUseInlineStrings = $optionsManager->getOption(Options::SHOULD_USE_INLINE_STRINGS);
|
$this->shouldUseInlineStrings = $optionsManager->getOption(Options::SHOULD_USE_INLINE_STRINGS);
|
||||||
$this->styleManager = $styleManager;
|
$this->styleManager = $styleManager;
|
||||||
$this->sharedStringsManager = $sharedStringsManager;
|
$this->sharedStringsManager = $sharedStringsManager;
|
||||||
$this->stringsEscaper = $stringsEscaper;
|
$this->stringsEscaper = $stringsEscaper;
|
||||||
$this->stringHelper = $stringHelper;
|
$this->stringHelper = $stringHelper;
|
||||||
|
$this->entityFactory = $entityFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -200,7 +207,7 @@ EOD;
|
|||||||
if ($cellValue instanceof Cell) {
|
if ($cellValue instanceof Cell) {
|
||||||
$cell = $cellValue;
|
$cell = $cellValue;
|
||||||
} else {
|
} else {
|
||||||
$cell = new Cell($cellValue);
|
$cell = $this->entityFactory->createCell($cellValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cell->isString()) {
|
if ($cell->isString()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user