Refactor readers for better di (#457)
* Refactor readers to get a proper DI Similar to what was done with writers, readers also needed to be updated to match the new way of doing things. This commits promotes a better DI (factories, injection through constructors). * Escapers should not be singletons Instead, they should be proper object that can be injected where needed.
This commit is contained in:
1 parent
4d6437fa77
commit
b7e46740ce
66 files changed
+1095
-618
No files matched your search
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\CSV\Creator;
|
||||
|
||||
use Box\Spout\Common\Creator\HelperFactory;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Reader\Common\Creator\EntityFactoryInterface;
|
||||
use Box\Spout\Reader\CSV\RowIterator;
|
||||
use Box\Spout\Reader\CSV\Sheet;
|
||||
use Box\Spout\Reader\CSV\SheetIterator;
|
||||
|
||||
/**
|
||||
* Class EntityFactory
|
||||
* Factory to create entities
|
||||
*
|
||||
* @package Box\Spout\Reader\CSV\Creator
|
||||
*/
|
||||
class EntityFactory implements EntityFactoryInterface
|
||||
{
|
||||
/** @var HelperFactory */
|
||||
private $helperFactory;
|
||||
|
||||
/**
|
||||
* @param HelperFactory $helperFactory
|
||||
*/
|
||||
public function __construct(HelperFactory $helperFactory)
|
||||
{
|
||||
$this->helperFactory = $helperFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $filePointer Pointer to the CSV file to read
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @return SheetIterator
|
||||
*/
|
||||
public function createSheetIterator($filePointer, $optionsManager, $globalFunctionsHelper)
|
||||
{
|
||||
return new SheetIterator($filePointer, $optionsManager, $globalFunctionsHelper, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $filePointer Pointer to the CSV file to read
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @return Sheet
|
||||
*/
|
||||
public function createSheet($filePointer, $optionsManager, $globalFunctionsHelper)
|
||||
{
|
||||
return new Sheet($filePointer, $optionsManager, $globalFunctionsHelper, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $filePointer Pointer to the CSV file to read
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @return RowIterator
|
||||
*/
|
||||
public function createRowIterator($filePointer, $optionsManager, $globalFunctionsHelper)
|
||||
{
|
||||
$encodingHelper = $this->helperFactory->createEncodingHelper($globalFunctionsHelper);
|
||||
return new RowIterator($filePointer, $optionsManager, $encodingHelper, $globalFunctionsHelper);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user