Favor object creation in factories (#459)
Instead of passing factories in the constructors and let objects call the factory method, create all dependencies directly in the factories.
This commit is contained in:
1 parent
4ec3a21170
commit
61f2addefa
13 files changed
+84
-114
No files matched your search
@@ -37,18 +37,19 @@ class EntityFactory implements EntityFactoryInterface
|
||||
*/
|
||||
public function createSheetIterator($filePointer, $optionsManager, $globalFunctionsHelper)
|
||||
{
|
||||
return new SheetIterator($filePointer, $optionsManager, $globalFunctionsHelper, $this);
|
||||
$rowIterator = $this->createRowIterator($filePointer, $optionsManager, $globalFunctionsHelper);
|
||||
$sheet = $this->createSheet($rowIterator);
|
||||
|
||||
return new SheetIterator($sheet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $filePointer Pointer to the CSV file to read
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @param RowIterator $rowIterator
|
||||
* @return Sheet
|
||||
*/
|
||||
public function createSheet($filePointer, $optionsManager, $globalFunctionsHelper)
|
||||
private function createSheet($rowIterator)
|
||||
{
|
||||
return new Sheet($filePointer, $optionsManager, $globalFunctionsHelper, $this);
|
||||
return new Sheet($rowIterator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +58,7 @@ class EntityFactory implements EntityFactoryInterface
|
||||
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @return RowIterator
|
||||
*/
|
||||
public function createRowIterator($filePointer, $optionsManager, $globalFunctionsHelper)
|
||||
private function createRowIterator($filePointer, $optionsManager, $globalFunctionsHelper)
|
||||
{
|
||||
$encodingHelper = $this->helperFactory->createEncodingHelper($globalFunctionsHelper);
|
||||
return new RowIterator($filePointer, $optionsManager, $encodingHelper, $globalFunctionsHelper);
|
||||
|
||||
@@ -16,14 +16,11 @@ class Sheet implements SheetInterface
|
||||
protected $rowIterator;
|
||||
|
||||
/**
|
||||
* @param resource $filePointer Pointer to the CSV file to read
|
||||
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager
|
||||
* @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
* @param RowIterator $rowIterator Corresponding row iterator
|
||||
*/
|
||||
public function __construct($filePointer, $optionsManager, $globalFunctionsHelper, $entityFactory)
|
||||
public function __construct(RowIterator $rowIterator)
|
||||
{
|
||||
$this->rowIterator = $entityFactory->createRowIterator($filePointer, $optionsManager, $globalFunctionsHelper);
|
||||
$this->rowIterator = $rowIterator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,14 +20,11 @@ class SheetIterator implements IteratorInterface
|
||||
protected $hasReadUniqueSheet = false;
|
||||
|
||||
/**
|
||||
* @param resource $filePointer
|
||||
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager
|
||||
* @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
* @param Sheet $sheet Corresponding unique sheet
|
||||
*/
|
||||
public function __construct($filePointer, $optionsManager, $globalFunctionsHelper, $entityFactory)
|
||||
public function __construct($sheet)
|
||||
{
|
||||
$this->sheet = $entityFactory->createSheet($filePointer, $optionsManager, $globalFunctionsHelper);
|
||||
$this->sheet = $sheet;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user