【php开源代码栏目提醒】:网学会员--在 php开源代码编辑为广大网友搜集整理了:request_handler.php绩等信息,祝愿广大网友取得需要的信息,参考学习。
<?php
/* SVN FILE: $Id: request_handler.php 4409 2007-02-02 13:20:59Z phpnut $ */
/**
* Request object for handling alternative HTTP requests
*
* Alternative HTTP requests can come from wireless units like mobile phones, palmtop computers, and the like.
* These units have no use for Ajax requests, and this Component can tell how Cake should respond to the different
* needs of a handheld computer and a desktop machine.
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp Cake
PHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.controller.components
* @since CakePHP(tm) v 0.10.4.1076
* @version $Revision: 4409 $
* @modifiedby $LastChangedBy: phpnut $
* @lastmodified $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
if (!defined('REQUEST_MOBILE_UA')) {
define('REQUEST_MOBILE_UA',
'(AvantGo|BlackBerry|DoCoMo|NetFront|Nokia|PalmOS|PalmSource|portalmmm|Plucker|ReqwirelessWeb|SonyEricsson|Symbian|UP\.Browser|Windows CE|Xiino)');
}
/**
* Request object for handling alternative HTTP requests
*
* @package cake
* @subpackage cake.cake.libs.controller.components
*
*/
class RequestHandlerComponent extends Object{
/**
* Enter description here...
*
* @var object
* @access public
*/
var $controller = true;
/**
* The layout that will be switched to for Ajax requests
*
* @var string
* @access public
* @see RequestHandler::setAjax()
*/
var $ajaxLayout = '
ajax';
/**
* Determines whether or not callbacks will be fired on this component
*
* @var boolean
* @access public
*/
var $disableStartup = false;
/**
* Friendly content-type mappings used to set response types and determine
* request types. Can be modified with RequestHandler::setContent()
*
* @var array
* @access private
* @see RequestHandlerComponent::setContent
*/
var $__requestContent = array(
'js' => 'text/javascript',
'css' => 'text/css',
'html' => 'text/html',
'form' => 'application/x-www-form-urlencoded',
'file' => 'multipart/form-data',
'xhtml' => array('application/xhtml+xml', 'application/xhtml', 'text/xhtml'),
'xml' => array('application/xml', 'text/xml'),
'rss' => 'application/rss+
xml',
'atom' => 'application/atom+xml'
);
/**
* Content-types accepted by the client. If extension parsing is enabled in the
* Router, and an extension is detected, the corresponding content-type will be
* used as the overriding primary content-type accepted.
*
* @var array
* @access private
*/
var $__acceptTypes = array();
/**
* Constructor. Parses the accepted content types accepted by the client using
* HTTP_ACCEPT
*
* @access public
* @return void
*/
function __construct() {
$this->__acceptTypes = explode(',', env('HTTP_ACCEPT'));
foreach($this->__acceptTypes as $i => $type) {
if (strpos($type, ';')) {
$type = explode(';', $type);
$this->__acceptTypes[$i] = $type[0];
}
}
parent::__construct();
}
/**
* Startup
*
* @param object A reference to the controller
* @return null
* @access public
*/
function startup(&$controller) {
if ($this->disableStartup) {
return;
}
$this->setAjax($controller);
}
/**
* Sets a controller's layout based on whether or not the current call is Ajax
*
* Add UTF-8 header for IE6 on XPsp2 bug if RequestHandlerComponent::isAjax()
*
* @param object The controller object
* @return null
* @access public
*/
function setAjax(&$controller) {
if ($this->isAjax()) {
$controller->layout = $this->ajaxLayout;
// Add UTF-8 header for IE6 on XPsp2 bug
header ('Content-Type: text/html; charset=UTF-8');
}
}
/**
* Returns true if the current call is from Ajax, false otherwise
*
* @return bool True if call is Ajax
* @access public
*/
function isAjax() {
if (env('HTTP_X_REQUESTED_WITH') != null) {
return env('HTTP_X_REQUESTED_WITH') == "XMLHttpRequest";
} else {
return false;
}
}
/**
* Returns true if the current call accepts an XML response, false otherwise
*
* @return bool True if client accepts an XML response
* @ac