|
5 | 5 | */
|
6 | 6 | namespace Magento\ImportExport\Model\Import\Source;
|
7 | 7 |
|
8 |
| -use Magento\Framework\Filesystem\Directory\Read; |
| 8 | +use Magento\Framework\Filesystem\Directory\Read as DirectoryRead; |
| 9 | +use Magento\Framework\Filesystem\File\ReadInterface as FileReadInterface; |
9 | 10 |
|
10 | 11 | /**
|
11 | 12 | * CSV import adapter
|
12 | 13 | */
|
13 | 14 | class Csv extends \Magento\ImportExport\Model\Import\AbstractSource
|
14 | 15 | {
|
15 | 16 | /**
|
16 |
| - * @var \Magento\Framework\Filesystem\File\Write |
| 17 | + * @var FileReadInterface |
17 | 18 | */
|
18 | 19 | protected $_file;
|
19 | 20 |
|
@@ -42,27 +43,33 @@ class Csv extends \Magento\ImportExport\Model\Import\AbstractSource
|
42 | 43 | *
|
43 | 44 | * There must be column names in the first line
|
44 | 45 | *
|
45 |
| - * @param string $file |
46 |
| - * @param Read $directory |
| 46 | + * @param string|FileReadInterface $file |
| 47 | + * @param DirectoryRead $directory |
47 | 48 | * @param string $delimiter
|
48 | 49 | * @param string $enclosure
|
49 | 50 | * @throws \LogicException
|
50 | 51 | */
|
51 | 52 | public function __construct(
|
52 | 53 | $file,
|
53 |
| - Read $directory, |
| 54 | + DirectoryRead $directory, |
54 | 55 | $delimiter = ',',
|
55 | 56 | $enclosure = '"'
|
56 | 57 | ) {
|
57 | 58 | // phpcs:ignore Magento2.Functions.DiscouragedFunction
|
58 | 59 | register_shutdown_function([$this, 'destruct']);
|
59 |
| - try { |
60 |
| - $this->filePath = $directory->getRelativePath($file); |
61 |
| - $this->_file = $directory->openFile($this->filePath, 'r'); |
| 60 | + if ($file instanceof FileReadInterface) { |
| 61 | + $this->filePath = ''; |
| 62 | + $this->_file = $file; |
62 | 63 | $this->_file->seek(0);
|
63 |
| - self::$openFiles[$this->filePath] = true; |
64 |
| - } catch (\Magento\Framework\Exception\FileSystemException $e) { |
65 |
| - throw new \LogicException("Unable to open file: '{$file}'"); |
| 64 | + } else { |
| 65 | + try { |
| 66 | + $this->filePath = $directory->getRelativePath($file); |
| 67 | + $this->_file = $directory->openFile($this->filePath, 'r'); |
| 68 | + $this->_file->seek(0); |
| 69 | + self::$openFiles[$this->filePath] = true; |
| 70 | + } catch (\Magento\Framework\Exception\FileSystemException $e) { |
| 71 | + throw new \LogicException("Unable to open file: '{$file}'"); |
| 72 | + } |
66 | 73 | }
|
67 | 74 | if ($delimiter) {
|
68 | 75 | $this->_delimiter = $delimiter;
|
|
0 commit comments