mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 19:38:26 +00:00
Adding RequestHandler::responseType() to get current response header, and adding automagic loading of helpers based on request content type
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3424 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
8041562a76
commit
419808f7df
1 changed files with 29 additions and 9 deletions
|
@ -46,7 +46,7 @@ class RequestHandlerComponent extends Object{
|
||||||
|
|
||||||
var $enabled = true;
|
var $enabled = true;
|
||||||
|
|
||||||
var $__responseTypeSet = false;
|
var $__responseTypeSet = null;
|
||||||
|
|
||||||
var $params = array();
|
var $params = array();
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ class RequestHandlerComponent extends Object{
|
||||||
'css' => 'text/css',
|
'css' => 'text/css',
|
||||||
'html' => array('text/html', '*/*'),
|
'html' => array('text/html', '*/*'),
|
||||||
'text' => 'text/plain',
|
'text' => 'text/plain',
|
||||||
|
'txt' => 'text/plain',
|
||||||
'form' => 'application/x-www-form-urlencoded',
|
'form' => 'application/x-www-form-urlencoded',
|
||||||
'file' => 'multipart/form-data',
|
'file' => 'multipart/form-data',
|
||||||
'xhtml' => array('application/xhtml+xml', 'application/xhtml', 'text/xhtml'),
|
'xhtml' => array('application/xhtml+xml', 'application/xhtml', 'text/xhtml'),
|
||||||
|
@ -133,6 +134,12 @@ class RequestHandlerComponent extends Object{
|
||||||
if (in_array($ext, array_keys($this->__requestContent))) {
|
if (in_array($ext, array_keys($this->__requestContent))) {
|
||||||
$this->respondAs($ext);
|
$this->respondAs($ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!in_array(ucfirst($ext), $controller->helpers)) {
|
||||||
|
if (file_exists(HELPERS . $ext . '.php') || fileExistsInPath(LIBS . 'view' . DS . 'helpers' . DS . $ext . '.php')) {
|
||||||
|
$controller->helpers[] = ucfirst($ext);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +162,7 @@ class RequestHandlerComponent extends Object{
|
||||||
*/
|
*/
|
||||||
function setAjax(&$controller) {
|
function setAjax(&$controller) {
|
||||||
if ($this->isAjax()) {
|
if ($this->isAjax()) {
|
||||||
$controller->layout=$this->ajaxLayout;
|
$controller->layout = $this->ajaxLayout;
|
||||||
|
|
||||||
// Add UTF-8 header for IE6 on XPsp2 bug
|
// Add UTF-8 header for IE6 on XPsp2 bug
|
||||||
header ('Content-Type: text/html; charset=UTF-8');
|
header ('Content-Type: text/html; charset=UTF-8');
|
||||||
|
@ -177,7 +184,7 @@ class RequestHandlerComponent extends Object{
|
||||||
* @return bool True if client accepts an XML response
|
* @return bool True if client accepts an XML response
|
||||||
*/
|
*/
|
||||||
function isXml() {
|
function isXml() {
|
||||||
return $this->accepts('xml');
|
return $this->prefers('xml');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns true if the current call accepts an RSS response, false otherwise
|
* Returns true if the current call accepts an RSS response, false otherwise
|
||||||
|
@ -185,7 +192,7 @@ class RequestHandlerComponent extends Object{
|
||||||
* @return bool True if client accepts an RSS response
|
* @return bool True if client accepts an RSS response
|
||||||
*/
|
*/
|
||||||
function isRss() {
|
function isRss() {
|
||||||
return $this->accepts('rss');
|
return $this->prefers('rss');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns true if the current call accepts an RSS response, false otherwise
|
* Returns true if the current call accepts an RSS response, false otherwise
|
||||||
|
@ -193,7 +200,7 @@ class RequestHandlerComponent extends Object{
|
||||||
* @return bool True if client accepts an RSS response
|
* @return bool True if client accepts an RSS response
|
||||||
*/
|
*/
|
||||||
function isAtom() {
|
function isAtom() {
|
||||||
return $this->accepts('atom');
|
return $this->prefers('atom');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns true if user agent string matches a mobile web browser, or if the client accepts WAP content
|
* Returns true if user agent string matches a mobile web browser, or if the client accepts WAP content
|
||||||
|
@ -209,7 +216,7 @@ class RequestHandlerComponent extends Object{
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function isWap() {
|
function isWap() {
|
||||||
return $this->accepts('wap');
|
return $this->prefers('wap');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns true if the current call a POST request
|
* Returns true if the current call a POST request
|
||||||
|
@ -392,7 +399,7 @@ class RequestHandlerComponent extends Object{
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function respondAs($type, $index = 0) {
|
function respondAs($type, $index = 0) {
|
||||||
if ($this->__responseTypeSet) {
|
if ($this->__responseTypeSet != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!array_key_exists($type, $this->__requestContent)) {
|
if (!array_key_exists($type, $this->__requestContent)) {
|
||||||
|
@ -421,17 +428,30 @@ class RequestHandlerComponent extends Object{
|
||||||
|
|
||||||
if ($cType != null) {
|
if ($cType != null) {
|
||||||
header('Content-type: ' . $cType);
|
header('Content-type: ' . $cType);
|
||||||
$this->__responseTypeSet = true;
|
$this->__responseTypeSet = $cType;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns the current response type (Content-type header), or null if none has been set
|
||||||
|
*
|
||||||
|
* @return mixed A string content type alias, or raw content type if no alias map exists,
|
||||||
|
* otherwise null
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function responseType() {
|
||||||
|
if ($this->__responseTypeSet == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $this->mapType($this->__responseTypeSet);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Maps a content-type back to an alias
|
* Maps a content-type back to an alias
|
||||||
*
|
*
|
||||||
* @param mixed $type
|
* @param mixed $type
|
||||||
* @returns mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function mapType($ctype) {
|
function mapType($ctype) {
|
||||||
|
|
Loading…
Reference in a new issue