Add helper functions to create specific readers and writers
Removed the `ReaderEntityFactory::createReader(Type)` method and replaced it by 3 methods: - `ReaderEntityFactory::createCSVReader()` - `ReaderEntityFactory::createXLSXReader()` - `ReaderEntityFactory::createODSReader()` This has the advantage of enabling autocomplete in the IDE, as the return type is no longer the interface but the concrete type. Since readers may expose different options, this is pretty useful. Similarly, removed the `WriterEntityFactory::createWriter(Type)` method and replaced it by 3 methods: - `WriterEntityFactory::createCSVWriter()` - `WriterEntityFactory::createXLSXWriter()` - `WriterEntityFactory::createODSWriter()` Since this is a breaking change, I also updated the Upgrade guide. Finally, the doc is up to date too.
This commit is contained in:
1 parent
6104d41857
commit
40ee386edd
30 files changed
+235
-275
No files matched your search
@@ -6,7 +6,6 @@ use Box\Spout\Common\Entity\Row;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Exception\SpoutException;
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\Reader\Wrapper\XMLReader;
|
||||
use Box\Spout\TestUsingResource;
|
||||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
||||
@@ -34,7 +33,7 @@ class WriterTest extends TestCase
|
||||
$this->createUnwritableFolderIfNeeded();
|
||||
$filePath = $this->getGeneratedUnwritableResourcePath($fileName);
|
||||
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
@$writer->openToFile($filePath);
|
||||
}
|
||||
|
||||
@@ -45,7 +44,7 @@ class WriterTest extends TestCase
|
||||
{
|
||||
$this->expectException(WriterNotOpenedException::class);
|
||||
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->addRow($this->createRowFromValues(['ods--11', 'ods--12']));
|
||||
}
|
||||
|
||||
@@ -56,7 +55,7 @@ class WriterTest extends TestCase
|
||||
{
|
||||
$this->expectException(WriterNotOpenedException::class);
|
||||
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->addRows([$this->createRowFromValues(['ods--11', 'ods--12'])]);
|
||||
}
|
||||
|
||||
@@ -70,8 +69,7 @@ class WriterTest extends TestCase
|
||||
$fileName = 'file_that_wont_be_written.ods';
|
||||
$filePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Writer\ODS\Writer $writer */
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->openToFile($filePath);
|
||||
|
||||
$writer->setTempFolder('');
|
||||
@@ -87,8 +85,7 @@ class WriterTest extends TestCase
|
||||
$fileName = 'file_that_wont_be_written.ods';
|
||||
$filePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Writer\ODS\Writer $writer */
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->openToFile($filePath);
|
||||
|
||||
$writer->setShouldCreateNewSheetsAutomatically(true);
|
||||
@@ -126,8 +123,7 @@ class WriterTest extends TestCase
|
||||
$this->recreateTempFolder();
|
||||
$tempFolderPath = $this->getTempFolderPath();
|
||||
|
||||
/** @var \Box\Spout\Writer\ODS\Writer $writer */
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->setTempFolder($tempFolderPath);
|
||||
$writer->openToFile($resourcePath);
|
||||
|
||||
@@ -151,8 +147,7 @@ class WriterTest extends TestCase
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var Writer $writer */
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->openToFile($resourcePath);
|
||||
$writer->addNewSheetAndMakeItCurrent();
|
||||
$writer->close();
|
||||
@@ -171,8 +166,7 @@ class WriterTest extends TestCase
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var Writer $writer */
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->openToFile($resourcePath);
|
||||
|
||||
$writer->addNewSheetAndMakeItCurrent();
|
||||
@@ -195,7 +189,7 @@ class WriterTest extends TestCase
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->close(); // This call should not cause any error
|
||||
|
||||
$writer->openToFile($resourcePath);
|
||||
@@ -349,8 +343,7 @@ class WriterTest extends TestCase
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Writer\ODS\Writer $writer */
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->openToFile($resourcePath);
|
||||
|
||||
$writer->addRows($dataRowsSheet1);
|
||||
@@ -485,8 +478,7 @@ class WriterTest extends TestCase
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Writer\ODS\Writer $writer */
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->setShouldCreateNewSheetsAutomatically($shouldCreateSheetsAutomatically);
|
||||
|
||||
$writer->openToFile($resourcePath);
|
||||
@@ -508,8 +500,7 @@ class WriterTest extends TestCase
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Writer\ODS\Writer $writer */
|
||||
$writer = WriterEntityFactory::createWriter(Type::ODS);
|
||||
$writer = WriterEntityFactory::createODSWriter();
|
||||
$writer->setShouldCreateNewSheetsAutomatically($shouldCreateSheetsAutomatically);
|
||||
|
||||
$writer->openToFile($resourcePath);
|
||||
|
||||
Reference in new issue
Block a user