Separate fopen into read and write methods
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
f1469e34aa
commit
6da2b7c4f6
|
@ -148,13 +148,25 @@ class SimpleFile implements ISimpleFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the file as stream, resulting resource can be operated as stream like the result from php's own fopen
|
* Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen
|
||||||
*
|
*
|
||||||
* @return resource
|
* @return resource
|
||||||
* @throws \OCP\Files\NotPermittedException
|
* @throws \OCP\Files\NotPermittedException
|
||||||
* @since 14.0.0
|
* @since 14.0.0
|
||||||
*/
|
*/
|
||||||
public function fopen(string $mode) {
|
public function read() {
|
||||||
return $this->file->fopen($mode);
|
return $this->file->fopen('r');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen
|
||||||
|
*
|
||||||
|
* @return resource
|
||||||
|
* @throws \OCP\Files\NotPermittedException
|
||||||
|
* @since 14.0.0
|
||||||
|
*/
|
||||||
|
public function write() {
|
||||||
|
return $this->file->fopen('w');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,11 +101,20 @@ interface ISimpleFile {
|
||||||
public function getMimeType();
|
public function getMimeType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the file as stream, resulting resource can be operated as stream like the result from php's own fopen
|
* Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen
|
||||||
*
|
*
|
||||||
* @return resource
|
* @return resource
|
||||||
* @throws \OCP\Files\NotPermittedException
|
* @throws \OCP\Files\NotPermittedException
|
||||||
* @since 14.0.0
|
* @since 14.0.0
|
||||||
*/
|
*/
|
||||||
public function fopen(string $mode);
|
public function read();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen
|
||||||
|
*
|
||||||
|
* @return resource
|
||||||
|
* @throws \OCP\Files\NotPermittedException
|
||||||
|
* @since 14.0.0
|
||||||
|
*/
|
||||||
|
public function write();
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,11 +124,19 @@ class SimpleFileTest extends \Test\TestCase {
|
||||||
$this->simpleFile->getContent();
|
$this->simpleFile->getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFopen() {
|
public function testRead() {
|
||||||
$this->file->expects($this->once())
|
$this->file->expects($this->once())
|
||||||
->method('fopen')
|
->method('fopen')
|
||||||
->with('r+');
|
->with('r');
|
||||||
|
|
||||||
$this->simpleFile->fopen('r+');
|
$this->simpleFile->read();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWrite() {
|
||||||
|
$this->file->expects($this->once())
|
||||||
|
->method('fopen')
|
||||||
|
->with('w');
|
||||||
|
|
||||||
|
$this->simpleFile->write();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue