tatter / exports
Modular file exports, for CodeIgniter 4
Fund package maintenance!
tattersoftware
paypal.me/tatter
Installs: 3 764
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: ^7.4 || ^8.0
- tatter/handlers: ^3.0
Requires (Dev)
- codeigniter4/devkit: ^1.0
- codeigniter4/framework: ^4.1
This package is auto-updated.
Last update: 2024-11-18 01:07:16 UTC
README
Modular file exports, for CodeIgniter 4
Quick Start
- Install with Composer:
> composer require tatter/exports
- Load a handler:
$handler = new \Tatter\Exports\Exports\DownloadHandler($myFile);
- Run the export:
return $handler->process();
Description
Exports defines small classes that can be used to direct files to various destinations.
Each class is a handler discoverable by Tatter\Handlers
with a distinct set of attributes
and its own doProcess()
method to do the actual export. Think of an export as something
you might see on a "share menu" from a mobile device: supported destinations for a file type.
Installation
Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities and always be up-to-date:
composer require tatter/exports
Or, install manually by downloading the source files and adding the directory to app/Config/Autoload.php.
Usage
You may load Export handlers directly, or use the ExportersFactory
to locate them based
on their attributes:
// Loaded directly $handler = new \Tatter\Exports\Exporters\DownloadExporter($myFile);` // Located by Handlers $class = ExporterFactory::find('download'); $exporter = new $class($myFile);
Every handler supports basic setters to provide your file and optional overrides for file metadata:
$exporter->setFile('/path/to/file'); // or... $file = new \CodeIgniter\Files\File('/path/to/file'); $exporter->setFile($file); $exporter->setFileName('RenameFileDuringExport.bam'); $exporter->setFileMime('overriding/mimetype');
To execute the export, call its process()
method, which will return a ResponseInterface
:
use Tatter\Exports\ExporterFactory; class MyController { public function previewFile($path) { $class = ExporterFactory::find('preview'); $exporter = new $class(); return $exporter->setFile($path)->process(); } }