From 0571391b10a48e6d6cbf8abfbe0d2e4a9fc26d0f Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Thu, 3 Mar 2022 05:10:57 +0000 Subject: Extend simple file with extension getter Signed-off-by: Christopher Ng --- lib/private/Files/SimpleFS/NewSimpleFile.php | 11 +++++++++++ lib/private/Files/SimpleFS/SimpleFile.php | 7 +++++++ lib/public/Files/SimpleFS/ISimpleFile.php | 5 +++++ lib/public/Files/SimpleFS/InMemoryFile.php | 7 +++++++ 4 files changed, 30 insertions(+) diff --git a/lib/private/Files/SimpleFS/NewSimpleFile.php b/lib/private/Files/SimpleFS/NewSimpleFile.php index f805403fd87..76fc69ebbe7 100644 --- a/lib/private/Files/SimpleFS/NewSimpleFile.php +++ b/lib/private/Files/SimpleFS/NewSimpleFile.php @@ -190,6 +190,17 @@ class NewSimpleFile implements ISimpleFile { } } + /** + * {@inheritDoc} + */ + public function getExtension(): string { + if ($this->file) { + return $this->file->getExtension(); + } else { + return \pathinfo($this->name, PATHINFO_EXTENSION); + } + } + /** * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen * diff --git a/lib/private/Files/SimpleFS/SimpleFile.php b/lib/private/Files/SimpleFS/SimpleFile.php index baf9b24e020..21a2fd92dcb 100644 --- a/lib/private/Files/SimpleFS/SimpleFile.php +++ b/lib/private/Files/SimpleFS/SimpleFile.php @@ -158,6 +158,13 @@ class SimpleFile implements ISimpleFile { return $this->file->getMimeType(); } + /** + * {@inheritDoc} + */ + public function getExtension(): string { + return $this->file->getExtension(); + } + /** * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen * diff --git a/lib/public/Files/SimpleFS/ISimpleFile.php b/lib/public/Files/SimpleFS/ISimpleFile.php index 3287c42054f..c0db4cc22e9 100644 --- a/lib/public/Files/SimpleFS/ISimpleFile.php +++ b/lib/public/Files/SimpleFS/ISimpleFile.php @@ -102,6 +102,11 @@ interface ISimpleFile { */ public function getMimeType(); + /** + * @since 24.0.0 + */ + public function getExtension(): string; + /** * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen * diff --git a/lib/public/Files/SimpleFS/InMemoryFile.php b/lib/public/Files/SimpleFS/InMemoryFile.php index 6020b42d953..4606fe9bd8a 100644 --- a/lib/public/Files/SimpleFS/InMemoryFile.php +++ b/lib/public/Files/SimpleFS/InMemoryFile.php @@ -126,6 +126,13 @@ class InMemoryFile implements ISimpleFile { return $fileInfo->buffer($this->contents); } + /** + * {@inheritDoc} + */ + public function getExtension(): string { + return \pathinfo($this->name, PATHINFO_EXTENSION); + } + /** * Stream reading is unsupported for in memory files. * -- cgit v1.2.3