Class AssetMiddleware

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.

Properties summary

  • $cacheTime protected
    string

    The amount of time to cache the asset.

  • $typeMap protected
    array

    A extension to content type mapping for plain text types.

Method Summary

Method Detail

__construct() public

__construct(array $options)

Constructor.

Parameters

array $options optional

The options to use

__invoke() public

__invoke(mixed $request, mixed $response, mixed $next)

Serve assets if the path matches one.

Parameters

\Psr\Http\Message\ServerRequestInterface $request

The request.

\Psr\Http\Message\ResponseInterface $response

The response.

callable $next

Callback to invoke the next middleware.

Returns

\Psr\Http\Message\ResponseInterface

A response

_getAssetFile() protected

_getAssetFile(mixed $url)

Builds asset file path based off url

Parameters

string $url

Asset URL

Returns

string|null

Absolute path for asset file, null on failure

deliverAsset() protected

deliverAsset(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, mixed $file)

Sends an asset file to the client

Parameters

\Psr\Http\Message\ServerRequestInterface $request

The request object to use.

\Psr\Http\Message\ResponseInterface $response

The response object to use.

\Cake\Filesystem\File $file

The file wrapper for the file.

Returns

\Psr\Http\Message\ResponseInterface

The response with the file & headers.

getType() protected

getType(mixed $file)

Return the type from a File object

Parameters

\Cake\Filesystem\File $file

The file from which you get the type

Returns

string

isNotModified() protected

isNotModified(mixed $request, mixed $file)

Check the not modified header.

Parameters

\Psr\Http\Message\ServerRequestInterface $request

The request to check.

\Cake\Filesystem\File $file

The file object to compare.

Returns

bool

Property Detail

$cacheTime protected

The amount of time to cache the asset.

Type

string

$typeMap protected

A extension to content type mapping for plain text types.

Because finfo doesn't give useful information for plain text types, we have to handle that here.

Type

array

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/class-Cake.Routing.Middleware.AssetMiddleware.html