diff --git a/src/Spout/Writer/Common/Creator/InternalFactoryInterface.php b/src/Spout/Writer/Common/Creator/InternalFactoryInterface.php index 7d085bf..dd0dd72 100644 --- a/src/Spout/Writer/Common/Creator/InternalFactoryInterface.php +++ b/src/Spout/Writer/Common/Creator/InternalFactoryInterface.php @@ -6,7 +6,7 @@ use Box\Spout\Writer\Common\Manager\OptionsManagerInterface; use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface; /** - * Interface GeneralFactoryInterface + * Interface InternalFactoryInterface * * @package Box\Spout\Writer\Common\Creator */ diff --git a/src/Spout/Writer/WriterAbstract.php b/src/Spout/Writer/WriterAbstract.php index e39842a..7569ff2 100644 --- a/src/Spout/Writer/WriterAbstract.php +++ b/src/Spout/Writer/WriterAbstract.php @@ -49,11 +49,17 @@ abstract class WriterAbstract implements WriterInterface /** * @param OptionsManagerInterface $optionsManager * @param StyleMerger $styleMerger + * @param GlobalFunctionsHelper $globalFunctionsHelper */ - public function __construct(OptionsManagerInterface $optionsManager, StyleMerger $styleMerger) + public function __construct( + OptionsManagerInterface $optionsManager, + StyleMerger $styleMerger, + GlobalFunctionsHelper $globalFunctionsHelper) { $this->optionsManager = $optionsManager; $this->styleMerger = $styleMerger; + $this->globalFunctionsHelper = $globalFunctionsHelper; + $this->resetRowStyleToDefault(); } @@ -97,16 +103,6 @@ abstract class WriterAbstract implements WriterInterface return $this; } - /** - * @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper - * @return WriterAbstract - */ - public function setGlobalFunctionsHelper($globalFunctionsHelper) - { - $this->globalFunctionsHelper = $globalFunctionsHelper; - return $this; - } - /** * Inits the writer and opens it to accept data. * By using this method, the data will be written to a file. diff --git a/src/Spout/Writer/WriterFactory.php b/src/Spout/Writer/WriterFactory.php index 6aae32d..4de04b5 100644 --- a/src/Spout/Writer/WriterFactory.php +++ b/src/Spout/Writer/WriterFactory.php @@ -28,25 +28,13 @@ class WriterFactory */ public static function create($writerType) { - $writer = null; - switch ($writerType) { - case Type::CSV: - $writer = self::getCSVWriter(); - break; - case Type::XLSX: - $writer = self::getXLSXWriter(); - break; - case Type::ODS: - $writer = self::getODSWriter(); - break; + case Type::CSV: return self::getCSVWriter(); + case Type::XLSX: return self::getXLSXWriter(); + case Type::ODS: return self::getODSWriter(); default: throw new UnsupportedTypeException('No writers supporting the given type: ' . $writerType); } - - $writer->setGlobalFunctionsHelper(new GlobalFunctionsHelper()); - - return $writer; } /** @@ -56,8 +44,9 @@ class WriterFactory { $optionsManager = new CSV\Manager\OptionsManager(); $styleMerger = new StyleMerger(); + $globalFunctionsHelper = new GlobalFunctionsHelper(); - return new CSV\Writer($optionsManager, $styleMerger); + return new CSV\Writer($optionsManager, $styleMerger, $globalFunctionsHelper); } /** @@ -68,9 +57,10 @@ class WriterFactory $styleBuilder = new StyleBuilder(); $optionsManager = new XLSX\Manager\OptionsManager($styleBuilder); $styleMerger = new StyleMerger(); - $generalFactory = new XLSX\Creator\InternalFactory(new EntityFactory()); + $globalFunctionsHelper = new GlobalFunctionsHelper(); + $internalFactory = new XLSX\Creator\InternalFactory(new EntityFactory()); - return new XLSX\Writer($optionsManager, $styleMerger, $generalFactory); + return new XLSX\Writer($optionsManager, $styleMerger, $globalFunctionsHelper, $internalFactory); } /** @@ -81,8 +71,9 @@ class WriterFactory $styleBuilder = new StyleBuilder(); $optionsManager = new ODS\Manager\OptionsManager($styleBuilder); $styleMerger = new StyleMerger(); - $generalFactory = new ODS\Creator\InternalFactory(new EntityFactory()); + $globalFunctionsHelper = new GlobalFunctionsHelper(); + $internalFactory = new ODS\Creator\InternalFactory(new EntityFactory()); - return new ODS\Writer($optionsManager, $styleMerger, $generalFactory); + return new ODS\Writer($optionsManager, $styleMerger, $globalFunctionsHelper, $internalFactory); } } diff --git a/src/Spout/Writer/WriterMultiSheetsAbstract.php b/src/Spout/Writer/WriterMultiSheetsAbstract.php index 3cb99a4..6d1e576 100644 --- a/src/Spout/Writer/WriterMultiSheetsAbstract.php +++ b/src/Spout/Writer/WriterMultiSheetsAbstract.php @@ -2,6 +2,7 @@ namespace Box\Spout\Writer; +use Box\Spout\Common\Helper\GlobalFunctionsHelper; use Box\Spout\Writer\Common\Manager\OptionsManagerInterface; use Box\Spout\Writer\Common\Entity\Options; use Box\Spout\Writer\Common\Entity\Worksheet; @@ -28,11 +29,16 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract /** * @param OptionsManagerInterface $optionsManager * @param StyleMerger $styleMerger + * @param GlobalFunctionsHelper $globalFunctionsHelper * @param InternalFactoryInterface $internalFactory */ - public function __construct(OptionsManagerInterface $optionsManager, StyleMerger $styleMerger, InternalFactoryInterface $internalFactory) + public function __construct( + OptionsManagerInterface $optionsManager, + StyleMerger $styleMerger, + GlobalFunctionsHelper $globalFunctionsHelper, + InternalFactoryInterface $internalFactory) { - parent::__construct($optionsManager, $styleMerger); + parent::__construct($optionsManager, $styleMerger, $globalFunctionsHelper); $this->internalFactory = $internalFactory; }