Class AssetDispatcher

Filters a request and tests whether it is a file in the webroot folder or not and serves the file to the client if appropriate.

DispatcherFilter implements CakeEventListener
Extended by AssetDispatcher
Package: Cake\Routing\Filter
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/Routing/Filter/AssetDispatcher.php

Properties summary

  • $priority public
    integer

    Default priority for all methods in this filter This filter should run before the request gets parsed by router

Inherited Properties

Method Summary

  • _deliverAsset() protected
    Sends an asset file to the client
  • _filterAsset() protected

    Checks if the client is requesting a filtered asset and runs the corresponding filter if any is configured

  • _getAssetFile() protected
    Builds asset file path based off url
  • Checks if a requested asset exists and sends it to the browser

Method Detail

_deliverAsset()source protected

_deliverAsset( CakeResponse $response , string $assetFile , string $ext )

Sends an asset file to the client

Parameters

CakeResponse $response
The response object to use.
string $assetFile
Path to the asset file in the file system
string $ext
The extension of the file to determine its mime type

_filterAsset()source protected

_filterAsset( CakeEvent $event )

Checks if the client is requesting a filtered asset and runs the corresponding filter if any is configured

Parameters

CakeEvent $event
containing the request and response object

Returns

CakeResponse
if the client is requesting a recognized asset, null otherwise

_getAssetFile()source protected

_getAssetFile( string $url )

Builds asset file path based off url

Parameters

string $url
URL

Returns

string
Absolute path for asset file

beforeDispatch()source public

beforeDispatch( CakeEvent $event )

Checks if a requested asset exists and sends it to the browser

Parameters

CakeEvent $event
containing the request and response object

Returns

mixed
The resulting response.

Throws

NotFoundException
When asset not found

Overrides

DispatcherFilter::beforeDispatch()

Methods inherited from DispatcherFilter

__construct()source public

__construct( array $settings array() )

Constructor.

Parameters

array $settings optional array()
Configuration settings for the filter.

afterDispatch()source public

afterDispatch( CakeEvent $event )

Method called after the controller served a request and generated a response. It is possible to alter the response object at this point as it is not sent to the client yet.

If false is returned, the event will be stopped and no more listeners will be notified. Alternatively you can call $event->stopPropagation() to achieve the same result.

Parameters

CakeEvent $event

container object having the request and response keys in the data property.

Returns

mixed
boolean to stop the event dispatching or null to continue

implementedEvents()source public

implementedEvents( )

Returns the list of events this filter listens to. Dispatcher notifies 2 different events Dispatcher.before and Dispatcher.after. By default this class will attach preDispatch and postDispatch method respectively.

Override this method at will to only listen to the events you are interested in.

Returns

array

Implementation of

CakeEventListener::implementedEvents()

Properties detail

$prioritysource

public integer

Default priority for all methods in this filter This filter should run before the request gets parsed by router

9

© 2005–2017 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/2.10/class-AssetDispatcher.html