1 Commits
0.1.1 ... 0.1.2

Author SHA1 Message Date
344324b47a Store contents to prevent reading file twice 2018-03-10 11:33:57 +01:00

View File

@@ -48,6 +48,10 @@ final class File extends Item
* @var bool * @var bool
*/ */
private $isEditable; private $isEditable;
/**
* @var string
*/
private $content = null;
/** /**
* PublicFile constructor. * PublicFile constructor.
@@ -82,7 +86,15 @@ final class File extends Item
$parent = substr($this->path, 0, $parentSep); $parent = substr($this->path, 0, $parentSep);
} else $parent = '/'; } else $parent = '/';
$this->parent = base64_encode($parent); $this->parent = base64_encode($parent);
if ($editable[$extension] ?? false && $file->read() !== false) {
$isEditable = $editable[$extension] ?? false;
$content = false;
if ($isEditable) {
$content = $file->read();
}
if ($isEditable && $content !== false) {
$this->content = $content;
$this->isEditable = true; $this->isEditable = true;
} else { } else {
$this->isEditable = false; $this->isEditable = false;
@@ -175,6 +187,7 @@ final class File extends Item
*/ */
public function getContents() public function getContents()
{ {
if ($this->content !== null) return $this->content;
return $this->file->read(); return $this->file->read();
} }