Skip to content

Commit 7f1da89

Browse files
author
Joan He
committed
MAGETWO-29705: Fixed confusing Filesystem Read/Write Interfaces
1 parent 42dfc8b commit 7f1da89

File tree

6 files changed

+20
-37
lines changed

6 files changed

+20
-37
lines changed

app/code/Magento/Downloadable/Helper/Download.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected function _getHandle()
168168
// Strip down protocol from path
169169
$path = preg_replace('#.+://#', '', $path);
170170
}
171-
$this->_handle = $this->fileReadFactory->createWithDriverCode($path, $protocol);
171+
$this->_handle = $this->fileReadFactory->create($path, $protocol);
172172
} elseif ($this->_linkType == self::LINK_TYPE_FILE) {
173173
$this->_workingDirectory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
174174
$fileExists = $this->_downloadableFile->ensureFileInFilesystem($this->_resourceFile);

dev/tests/unit/testsuite/Magento/Framework/Filesystem/File/ReadFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testCreateWithDriverCode()
3030
$driverMock->expects($this->any())->method('isExists')->willReturn(true);
3131
$driverPool->expects($this->once())->method('getDriver')->willReturn($driverMock);
3232
$factory = new ReadFactory($driverPool);
33-
$result = $factory->createWithDriverCode('path', 'driverCode');
33+
$result = $factory->create('path', 'driverCode');
3434
$this->assertInstanceOf('Magento\Framework\Filesystem\File\Read', $result);
3535
}
3636
}

dev/tests/unit/testsuite/Magento/Framework/Filesystem/File/WriteFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCreateWithDriverCode()
2828
$driverMock->expects($this->any())->method('isExists')->willReturn(true);
2929
$driverPool->expects($this->once())->method('getDriver')->willReturn($driverMock);
3030
$factory = new WriteFactory($driverPool);
31-
$result = $factory->createWithDriverCode('path', 'driverCode');
31+
$result = $factory->create('path', 'driverCode');
3232
$this->assertInstanceOf('Magento\Framework\Filesystem\File\Write', $result);
3333
}
3434

lib/internal/Magento/Framework/Filesystem.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,23 @@ public function __construct(
5252
}
5353

5454
/**
55-
* Create an instance of directory with write permissions
55+
* Create an instance of directory with read permissions
5656
*
57-
* @param string $code
57+
* @param string $directoryCode
58+
* @param string $driverCode
5859
* @return \Magento\Framework\Filesystem\Directory\ReadInterface
5960
*/
60-
public function getDirectoryRead($code)
61+
public function getDirectoryRead($directoryCode, $driverCode = DriverPool::FILE)
6162
{
63+
$code = $directoryCode . '_' . $driverCode;
6264
if (!array_key_exists($code, $this->readInstances)) {
63-
$this->readInstances[$code] = $this->readFactory->create($this->getDirPath($code));
65+
$this->readInstances[$code] = $this->readFactory->create($this->getDirPath($directoryCode), $driverCode);
6466
}
6567
return $this->readInstances[$code];
6668
}
6769

6870
/**
69-
* Create an instance of directory with read permissions
71+
* Create an instance of directory with write permissions
7072
*
7173
* @param string $directoryCode
7274
* @param string $driverCode

lib/internal/Magento/Framework/Filesystem/File/ReadFactory.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,14 @@ public function __construct(DriverPool $driverPool)
3131
* Create a readable file
3232
*
3333
* @param string $path
34-
* @param DriverInterface $driver
34+
* @param DriverInterface|string $driver Driver or driver code
3535
* @return \Magento\Framework\Filesystem\File\ReadInterface
3636
*/
37-
public function create($path, DriverInterface $driver = null)
37+
public function create($path, $driver)
3838
{
39+
if (is_string($driver)) {
40+
return new Read($path, $this->driverPool->getDriver($driver));
41+
}
3942
return new Read($path, $driver);
4043
}
41-
42-
/**
43-
* Create a readable file
44-
*
45-
* @param string $path
46-
* @param string|null $driverCode
47-
* @return \Magento\Framework\Filesystem\File\ReadInterface
48-
*/
49-
public function createWithDriverCode($path, $driverCode)
50-
{
51-
return new Read($path, $this->driverPool->getDriver($driverCode));
52-
}
5344
}

lib/internal/Magento/Framework/Filesystem/File/WriteFactory.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,15 @@ public function __construct(DriverPool $driverPool)
3131
* Create a readable file.
3232
*
3333
* @param string $path
34-
* @param DriverInterface $driver
34+
* @param DriverInterface|string $driver Driver or driver code
3535
* @param string $mode [optional]
3636
* @return Write
3737
*/
38-
public function create($path, DriverInterface $driver, $mode = 'r')
38+
public function create($path, $driver, $mode = 'r')
3939
{
40+
if (is_string($driver)) {
41+
return new Write($path, $this->driverPool->getDriver($driver), $mode);
42+
}
4043
return new Write($path, $driver, $mode);
4144
}
42-
43-
/**
44-
* Create a readable file.
45-
*
46-
* @param string $path
47-
* @param string $driverCode
48-
* @param string $mode [optional]
49-
* @return Write
50-
*/
51-
public function createWithDriverCode($path, $driverCode, $mode = 'r')
52-
{
53-
return new Write($path, $this->driverPool->getDriver($driverCode), $mode);
54-
}
5545
}

0 commit comments

Comments
 (0)