mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-15 22:16:32 +02:00
MINOR Moved static functions in ContentNegotiator above the instance methods
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@93641 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
b26b7e1228
commit
bd37d67a48
@ -54,6 +54,27 @@ class ContentNegotiator {
|
|||||||
return self::$encoding;
|
return self::$encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable content negotiation for all templates, not just those with the xml header.
|
||||||
|
*/
|
||||||
|
static function enable() {
|
||||||
|
self::$enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if negotation is enabled for the given response.
|
||||||
|
* By default, negotiation is only enabled for pages that have the xml header.
|
||||||
|
*/
|
||||||
|
static function enabled_for($response) {
|
||||||
|
$contentType = $response->getHeader("Content-Type");
|
||||||
|
|
||||||
|
// Disable content negotation for other content types
|
||||||
|
if($contentType && substr($contentType, 0,9) != 'text/html' && substr($contentType, 0,21) != 'application/xhtml+xml') return false;
|
||||||
|
|
||||||
|
if(self::$enabled) return true;
|
||||||
|
else return (substr($response->getBody(),0,5) == '<' . '?xml');
|
||||||
|
}
|
||||||
|
|
||||||
static function process(SS_HTTPResponse $response) {
|
static function process(SS_HTTPResponse $response) {
|
||||||
if(!self::enabled_for($response)) return;
|
if(!self::enabled_for($response)) return;
|
||||||
|
|
||||||
@ -160,27 +181,4 @@ class ContentNegotiator {
|
|||||||
$response->setBody($content);
|
$response->setBody($content);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable content negotiation for all templates, not just those with the xml header.
|
|
||||||
*/
|
|
||||||
static function enable() {
|
|
||||||
self::$enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if negotation is enabled for the given response.
|
|
||||||
* By default, negotiation is only enabled for pages that have the xml header.
|
|
||||||
*/
|
|
||||||
static function enabled_for($response) {
|
|
||||||
$contentType = $response->getHeader("Content-Type");
|
|
||||||
|
|
||||||
// Disable content negotation for other content types
|
|
||||||
if($contentType && substr($contentType, 0,9) != 'text/html' && substr($contentType, 0,21) != 'application/xhtml+xml') return false;
|
|
||||||
|
|
||||||
if(self::$enabled) return true;
|
|
||||||
else return (substr($response->getBody(),0,5) == '<' . '?xml');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
Loading…
Reference in New Issue
Block a user