mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
adding options for react to response when asset not exists
This commit is contained in:
parent
0906dec3c4
commit
40b7694891
1 changed files with 9 additions and 2 deletions
|
@ -38,7 +38,8 @@ class AssetDispatcher extends DispatcherFilter {
|
|||
* Checks if a requested asset exists and sends it to the browser
|
||||
*
|
||||
* @param CakeEvent $event containing the request and response object
|
||||
* @return CakeResponse if the client is requesting a recognized asset, null otherwise
|
||||
* @return mixed The resulting response.
|
||||
* @throws NotFoundException When asset not found
|
||||
*/
|
||||
public function beforeDispatch(CakeEvent $event) {
|
||||
$url = urldecode($event->data['request']->url);
|
||||
|
@ -52,13 +53,19 @@ class AssetDispatcher extends DispatcherFilter {
|
|||
}
|
||||
|
||||
$assetFile = $this->_getAssetFile($url);
|
||||
if ($assetFile === null || !file_exists($assetFile)) {
|
||||
if ($assetFile === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$response = $event->data['response'];
|
||||
$event->stopPropagation();
|
||||
|
||||
if (!file_exists($assetFile)) {
|
||||
$response->statusCode(404);
|
||||
$response->send();
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response->modified(filemtime($assetFile));
|
||||
if ($response->checkNotModified($event->data['request'])) {
|
||||
return $response;
|
||||
|
|
Loading…
Reference in a new issue