ENHANCEMENT: Added HTTPRequest->isMedia() to check if a request is for a common media type.

From: Andrew Short <andrewjshort@gmail.com>

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88478 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew Short 2009-10-11 00:07:02 +00:00 committed by Sam Minnee
parent cf2cf11b57
commit 490835633c
1 changed files with 14 additions and 1 deletions

View File

@ -177,6 +177,19 @@ class HTTPRequest extends Object implements ArrayAccess {
return $this->extension;
}
/**
* Checks if the {@link HTTPRequest->getExtension()} on this request matches one of the more common media types
* embedded into a webpage - e.g. css, png.
*
* This is useful for things like determining wether to display a fully rendered error page or not. Note that the
* media file types is not at all comprehensive.
*
* @return bool
*/
public function isMedia() {
return in_array($this->getExtension(), array('css', 'js', 'jpg', 'jpeg', 'gif', 'png', 'bmp', 'ico'));
}
/**
* Add a HTTP header to the response, replacing any header of the same name.
*
@ -497,4 +510,4 @@ class HTTPRequest extends Object implements ArrayAccess {
return $origMethod;
}
}
}
}