AssetMiddleware
in package
implements
MiddlewareInterface
Handles serving plugin assets in development mode.
This should not be used in production environments as it has sub-optimal performance when compared to serving files with a real webserver.
Table of Contents
Interfaces
- MiddlewareInterface
- Participant in processing a server request and response.
Properties
- $cacheTime : string
- The amount of time to cache the asset.
Methods
- __construct() : mixed
- Constructor.
- process() : ResponseInterface
- Serve assets if the path matches one.
- _getAssetFile() : string|null
- Builds asset file path based off url
- deliverAsset() : Response
- Sends an asset file to the client
- isNotModified() : bool
- Check the not modified header.
Properties
$cacheTime
The amount of time to cache the asset.
protected
string
$cacheTime
= '+1 day'
Methods
__construct()
Constructor.
public
__construct([array<string, mixed> $options = [] ]) : mixed
Parameters
- $options : array<string, mixed> = []
-
The options to use
process()
Serve assets if the path matches one.
public
process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
Parameters
- $request : ServerRequestInterface
-
The request.
- $handler : RequestHandlerInterface
-
The request handler.
Return values
ResponseInterface —A response.
_getAssetFile()
Builds asset file path based off url
protected
_getAssetFile(string $url) : string|null
Parameters
- $url : string
-
Asset URL
Return values
string|null —Absolute path for asset file, null on failure
deliverAsset()
Sends an asset file to the client
protected
deliverAsset(ServerRequestInterface $request, SplFileInfo $file) : Response
Parameters
- $request : ServerRequestInterface
-
The request object to use.
- $file : SplFileInfo
-
The file wrapper for the file.
Return values
Response —The response with the file & headers.
isNotModified()
Check the not modified header.
protected
isNotModified(ServerRequestInterface $request, SplFileInfo $file) : bool
Parameters
- $request : ServerRequestInterface
-
The request to check.
- $file : SplFileInfo
-
The file object to compare.