Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smichaelsen/typo3-fal-filewriter
Handy class to generate files in a TYPO3 FAL environment
https://github.com/smichaelsen/typo3-fal-filewriter
Last synced: about 2 months ago
JSON representation
Handy class to generate files in a TYPO3 FAL environment
- Host: GitHub
- URL: https://github.com/smichaelsen/typo3-fal-filewriter
- Owner: smichaelsen
- Created: 2016-08-01T12:46:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-16T06:00:25.000Z (over 7 years ago)
- Last Synced: 2024-04-24T03:14:56.027Z (9 months ago)
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FAL Filewriter [![Build Status](https://travis-ci.org/smichaelsen/typo3-fal-filewriter.svg?branch=master)](https://travis-ci.org/smichaelsen/typo3-fal-filewriter)
Little helper package for when you want to create files and save them to TYPO3's File Abstraction Layer
## Installation
FAL Filewriter is no TYPO3 extension and not available via TER. It can only be installed via composer:
`composer require smichaelsen/fal-filewriter`
## Usage
### FileGenerator
You need to create a class that provides the content that will be saved in a file. It has to implement the
`\Smichaelsen\FalFilewriter\FileGeneratorInterface`, which is fairly easy.### Storage
By default your TYPO3 installation will have a storage record with uid `1` pointing to the fileadmin, but of course you
can configure your own storage records pointing to other folders or even to external services like AWS.Load the storage object like this:
$storage = $this->objectManager->get(\TYPO3\CMS\Core\Resource\StorageRepository::class)->findByUid($fileStorageUid);
### FileWriterServiceThe `\Smichaelsen\FalFilewriter\FileWriterService` has one public method `saveFile()` which takes the following parameters:
* **$fileGenerator**: Your file generator object implementing the `FileGeneratorInterface`.
* **$fileIdentifier**: The file name which may include a relative path inside the `$storage` folder. The file extension
may be omitted. Then it is read from the `$fileGenerator` (`->getFileExtension()`). If the file name starts with a path
that doesn't exist it will be tried to create that path.
* **$storage**: The `ResourceStorage` object to save the file in. See above ("Storage") for more information.As return value you will receive a `\TYPO3\CMS\Core\Resource\FileInterface` object for the saved file.
Example:
/** @var \Smichaelsen\FalFilewriter\FileWriterService $fileWriterService */
/** @var \Smichaelsen\FalFilewriter\FileGeneratorInterface $fileGenerator */
/** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storage */
$fileObject = $fileWriterService->saveFile($fileGenerator, 'folder/my-filename', $storage);