From e5c3e4b76fac1c4a1235781229486f53ffcb93c1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 29 Oct 2018 15:23:33 +0100 Subject: [PATCH] Add getExtension() to FileInfo this is a fairly common operation so it makes sense to prevent having to repeatedly implement it. Signed-off-by: Robin Appelman --- apps/files_trashbin/lib/Trash/TrashItem.php | 4 ++++ lib/private/Files/FileInfo.php | 4 ++++ lib/private/Files/Node/File.php | 4 ++++ lib/private/Files/Node/LazyRoot.php | 4 ++++ lib/private/Files/Node/Node.php | 4 ++++ lib/public/Files/File.php | 8 ++++++++ lib/public/Files/FileInfo.php | 8 ++++++++ 7 files changed, 36 insertions(+) diff --git a/apps/files_trashbin/lib/Trash/TrashItem.php b/apps/files_trashbin/lib/Trash/TrashItem.php index cd7079bcf2..40ceb59aba 100644 --- a/apps/files_trashbin/lib/Trash/TrashItem.php +++ b/apps/files_trashbin/lib/Trash/TrashItem.php @@ -169,4 +169,8 @@ class TrashItem implements ITrashItem { public function getChecksum() { return $this->fileInfo->getChecksum(); } + + public function getExtension(): string { + return $this->fileInfo->getExtension(); + } } diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php index 53f73f0f95..575af56ceb 100644 --- a/lib/private/Files/FileInfo.php +++ b/lib/private/Files/FileInfo.php @@ -390,4 +390,8 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { public function getChecksum() { return $this->data['checksum']; } + + public function getExtension(): string { + return pathinfo($this->getName(), PATHINFO_EXTENSION); + } } diff --git a/lib/private/Files/Node/File.php b/lib/private/Files/Node/File.php index 7c411620ca..a3eabbcc44 100644 --- a/lib/private/Files/Node/File.php +++ b/lib/private/Files/Node/File.php @@ -142,4 +142,8 @@ class File extends Node implements \OCP\Files\File { public function getChecksum() { return $this->getFileInfo()->getChecksum(); } + + public function getExtension(): string { + return $this->getFileInfo()->getExtension(); + } } diff --git a/lib/private/Files/Node/LazyRoot.php b/lib/private/Files/Node/LazyRoot.php index faa57ecb0b..389a1a9f0f 100644 --- a/lib/private/Files/Node/LazyRoot.php +++ b/lib/private/Files/Node/LazyRoot.php @@ -344,6 +344,10 @@ class LazyRoot implements IRootFolder { return $this->__call(__FUNCTION__, func_get_args()); } + public function getExtension(): string { + return $this->__call(__FUNCTION__, func_get_args()); + } + /** * @inheritDoc */ diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index d2232624b9..590f108061 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -354,6 +354,10 @@ class Node implements \OCP\Files\Node { public function getChecksum() { } + public function getExtension(): string { + return $this->getFileInfo()->getExtension(); + } + /** * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE * @throws \OCP\Lock\LockedException diff --git a/lib/public/Files/File.php b/lib/public/Files/File.php index ad2cb7b55c..29a83b4df7 100644 --- a/lib/public/Files/File.php +++ b/lib/public/Files/File.php @@ -96,4 +96,12 @@ interface File extends Node { * @throws NotFoundException */ public function getChecksum(); + + /** + * Get the extension of this file + * + * @return string + * @since 15.0.0 + */ + public function getExtension(): string; } diff --git a/lib/public/Files/FileInfo.php b/lib/public/Files/FileInfo.php index 1fe71b356c..e25a47e83c 100644 --- a/lib/public/Files/FileInfo.php +++ b/lib/public/Files/FileInfo.php @@ -259,4 +259,12 @@ interface FileInfo { * @since 9.0.0 */ public function getChecksum(); + + /** + * Get the extension of the file + * + * @return string + * @since 15.0.0 + */ + public function getExtension(): string; }