Update Reader/WriterEntityFactory

Add `WriterEntityFactory::createWriterFromFile`, working like `ReaderEntityFactory::createReaderFromFile` (guessing writer type from file name).
Use static functions when needed.
This commit is contained in:
Adrien Loison authored and Adrien Loison committed 2019-05-17 13:22:27 +02:00
1 parent e8693834a0
commit 4a9d0398ad
6 files changed
+124 -19

No files matched your search

@@ -60,21 +60,21 @@ class ReaderFactory
/**
* Creates a reader by file extension
*
* @param string The path to the spreadsheet file. Supported extensions are .csv,.ods and .xlsx
* @param string $path The path to the spreadsheet file. Supported extensions are .csv,.ods and .xlsx
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
* @return ReaderInterface
*/
public static function createFromFile(string $path)
{
if (!\is_file($path)) {
if (!is_file($path)) {
throw new IOException(
sprintf('Could not open "%s" for reading! File does not exist.', $path)
);
}
$ext = \pathinfo($path, PATHINFO_EXTENSION);
$ext = \strtolower($ext);
$ext = pathinfo($path, PATHINFO_EXTENSION);
$ext = strtolower($ext);
$readerType = self::$extensionReaderMap[$ext] ?? null;
if ($readerType === null) {
throw new UnsupportedTypeException(