ThinkPHP/Library/Think/Controller/RestController.class.php

(开头部分) 8KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace Think\Controller;
use Think\Controller;
use Think\App;
/**
 * ThinkPHP REST控制器类
 */
class RestController extends Controller {
    // 当前请求类型
    protected   $_method        =   ''; 
    // 当前请求的资源类型
    protected   $_type          =   ''; 
    // REST允许的请求类型列表
    protected   $allowMethod    =   array('get','post','put','delete'); 
    // REST默认请求类型
    protected   $defaultMethod  =   'get';
    // REST允许请求的资源类型列表
    protected   $allowType      =   array('html','xml','json','rss'); 
    // 默认的资源类型
    protected   $defaultType    =   'html';
    // REST允许输出的资源类型列表
    protected   $allowOutputType=   array(  
                    'xml' => 'application/xml',
                    'json' => 'application/json',
                    'html' => 'text/html',
                );

   /**
     * 架构函数
     * @access public
     */
    public function __construct() {
        // 资源类型检测
        if(''==__EXT__) { // 自动检测资源类型
            $this->_type   =  $this->getAcceptType();
        }elseif(!in_array(__EXT__,$this->allowType)) {
            // 资源类型非法 则用默认资源类型访问
            $this->_type   =  $this->defaultType;
        }else{
            $this->_type   =  __EXT__ ;
        }

        // 请求方式检测
        $method  =  strtolower(REQUEST_METHOD);
        if(!in_array($method,$this->allowMethod)) {
            // 请求方式非法 则用默认请求方法
            $method = $this->defaultMethod;
        }
        $this->_method = $method;
        
        parent::__construct();
后面还有 174 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。