Download the PHP package middlewares/filesystem without Composer
On this page you can find all versions of the php package middlewares/filesystem. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download middlewares/filesystem
More information about middlewares/filesystem
Files in middlewares/filesystem
Package filesystem
Short Description Middleware to save or read responses using Flysystem
License MIT
Homepage https://github.com/middlewares/filesystem
Informations about the package filesystem
middlewares/filesystem
Middleware to save or read responses from files. It uses Flysystem as filesystem handler, so you can use not only a local directories, but also any other adapter like ftp, sftp, dropbox, etc... This package includes the following components:
- Reader
- Writer
Requirements
- PHP >= 7.2
- A PSR-7 http library
- A PSR-15 middleware dispatcher
Installation
This package is installable and autoloadable via Composer as middlewares/filesystem.
Example
Reader
To read the response body from a file under the following conditions:
- Only
GET
methods are allowed, returning a405
code otherwise. - If the request path has no extension, assume it's a directory and append
/index.html
. For example: if the request path is/post/23
, the file used is/post/23/index.html
. - It can handle gzipped files. For example, if
/post/23/index.html
does not exists but/post/23/index.html.gz
is available and the request headerAccept-Encoding
containsgzip
, returns it. Accept-Ranges
is also supported, useful to server big files like videos.
Example using a ftp storage:
Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface
and Psr\Http\Message\StreamFactoryInterface
, that will be used to create the response and stream. If they are not not defined, Middleware\Utils\Factory will be used to detect them automatically.
continueOnError
Allows to continue to the next middleware on error (file not found, method not allowed, etc). This allows to create a simple caching system as the following:
Writer
Saves the response content into a file if all of the following conditions are met:
- The method is
GET
- The status code is
200
- The
Cache-Control
header does not containno-cache
andno-store
To be compatible with Reader
behaviour:
- If the request path has no extension, assume it's a directory and append
/index.html
. For example: if the request path is/post/23
, the file saved is/post/23/index.html
. - If the response is gzipped (has the header
Content-Encoding: gzip
) the file is saved with the extension .gz. For example/post/23/index.html.gz
(instead/post/23/index.html
).
Optionally, you can provide a Psr\Http\Message\StreamFactoryInterface
as the second that will be used to create a new body to the response. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.
Helpers
createFromDirectory
Both Reader
and Writer
have a static method as a shortcut to create instances using a directory in the local filesystem, due this is the most common case:
Please see CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.
All versions of filesystem with dependencies
middlewares/utils Version ^3.0
league/flysystem Version ^1.0
psr/http-server-middleware Version ^1.0