Project

General

Profile

Actions

Feature #93209

closed

Add getFile() to TYPO3\CMS\Core\Resource\Folder

Added by Ingo Reuter almost 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
File Abstraction Layer (FAL)
Target version:
-
Start date:
2021-01-03
Due date:
% Done:

100%

Estimated time:
PHP Version:
Tags:
Complexity:
easy
Sprint Focus:

Description

Working with Files and Folders in FAL is quite convenient. The class TYPO3\CMS\Core\Resource\Folder offers many methods for getting folders and files inside a specific folder.

The class allows to retrieve a list of all files inside a folder, a list of subfolders, to create a new file inside the folder and many more. It is even possible to get a specific folder inside the current folder (via $folder->getSubfolder("folderName")). Unfortunately the equivalent method does not exist for files. It would be handy to have something like $folder->getFile("filename.ext") instead of calling $folder->getStorage()->getFileInFolder("filename.ext", $folder). It might be mentioned, that the method hasFile(..) is already implemented.

My suggestion is to add the following method to TYPO3\CMS\Core\Resource\Folder

public function getFile($fileName) {
    if (!$this->storage->hasFileInFolder($fileName, $this)) {
            throw new \InvalidArgumentException('File "' . $fileName . '" does not exist in "' . $this->identifier . '"', 1609714577);
    }
    return $this->storage->getFileInFolder($fileName, $this);
}
Actions

Also available in: Atom PDF