Merge pull request #31418 from nextcloud/enh/simple-file-extension

This commit is contained in:
Pytal 2022-03-07 11:38:23 -08:00 committed by GitHub
commit 232af474a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 1 deletions

View file

@ -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
*

View file

@ -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
*

View file

@ -28,7 +28,11 @@ use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
/**
* Interface ISimpleFile
* This interface allows to manage simple files.
*
* This interface must not be implemented in your application but
* instead should be used as a service and injected in your code with
* dependency injection.
*
* @since 11.0.0
*/
@ -102,6 +106,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
*

View file

@ -126,6 +126,14 @@ class InMemoryFile implements ISimpleFile {
return $fileInfo->buffer($this->contents);
}
/**
* {@inheritDoc}
* @since 24.0.0
*/
public function getExtension(): string {
return \pathinfo($this->name, PATHINFO_EXTENSION);
}
/**
* Stream reading is unsupported for in memory files.
*