点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 行业软件>> 在线考试系统>> 源文件浏览
[免费版 Free] WebForm,下载次数:349 次 | 关键字: 考试 办公 高校 竞赛 企事业单位

源码截图

源码目录树

;
当前路径:vendor/topthink/framework/src/think/route/Domain.php
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace think\route;

use think\helper\Str;
use think\Request;
use think\Route;
use think\route\dispatch\Callback as CallbackDispatch;
use think\route\dispatch\Controller as ControllerDispatch;

/**
 * 鍩熷悕璺敱
 */
class Domain extends RuleGroup
{
    /**
     * 鏋舵瀯鍑芥暟
     * @access public
     * @param  Route       $router   璺敱瀵硅薄
     * @param  string      $name     璺敱鍩熷悕
     * @param  mixed       $rule     鍩熷悕璺敱
     */
    public function __construct(Route $router, string $name = null, $rule = null)
    {
        $this->router = $router;
        $this->domain = $name;
        $this->rule   = $rule;
    }

    /**
     * 妫€娴嬪煙鍚嶈矾鐢?     * @access public
     * @param  Request      $request  璇锋眰瀵硅薄
     * @param  string       $url      璁块棶鍦板潃
     * @param  bool         $completeMatch   璺敱鏄惁瀹屽叏鍖归厤
     * @return Dispatch|false
     */
    public function check(Request $request, string $url, bool $completeMatch = false)
    {
        // 妫€娴婾RL缁戝畾
        $result = $this->checkUrlBind($request, $url);

        if (!empty($this->option['append'])) {
            $request->setRoute($this->option['append']);
            unset($this->option['append']);
        }

        if (false !== $result) {
            return $result;
        }

        return parent::check($request, $url, $completeMatch);
    }

    /**
     * 璁剧疆璺敱缁戝畾
     * @access public
     * @param  string     $bind 缁戝畾淇℃伅
     * @return $this
     */
    public function bind(string $bind)
    {
        $this->router->bind($bind, $this->domain);

        return $this;
    }

    /**
     * 妫€娴婾RL缁戝畾
     * @access private
     * @param  Request   $request
     * @param  string    $url URL鍦板潃
     * @return Dispatch|false
     */
    private function checkUrlBind(Request $request, string $url)
    {
        $bind = $this->router->getDomainBind($this->domain);

        if ($bind) {
            $this->parseBindAppendParam($bind);

            // 濡傛灉鏈塙RL缁戝畾 鍒欒繘琛岀粦瀹氭娴?            $type = substr($bind, 0, 1);
            $bind = substr($bind, 1);

            $bindTo = [
                '\\' => 'bindToClass',
                '@'  => 'bindToController',
                ':'  => 'bindToNamespace',
            ];

            if (isset($bindTo[$type])) {
                return $this->{$bindTo[$type]}($request, $url, $bind);
            }
        }

        return false;
    }

    protected function parseBindAppendParam(string &$bind): void
    {
        if (false !== strpos($bind, '?')) {
            [$bind, $query] = explode('?', $bind);
            parse_str($query, $vars);
            $this->append($vars);
        }
    }

    /**
     * 缁戝畾鍒扮被
     * @access protected
     * @param  Request   $request
     * @param  string    $url URL鍦板潃
     * @param  string    $class 绫诲悕锛堝甫鍛藉悕绌洪棿锛?     * @return CallbackDispatch
     */
    protected function bindToClass(Request $request, string $url, string $class): CallbackDispatch
    {
        $array  = explode('|', $url, 2);
        $action = !empty($array[0]) ? $array[0] : $this->router->config('default_action');
        $param  = [];

        if (!empty($array[1])) {
            $this->parseUrlParams($array[1], $param);
        }

        return new CallbackDispatch($request, $this, [$class, $action], $param);
    }

    /**
     * 缁戝畾鍒板懡鍚嶇┖闂?     * @access protected
     * @param  Request   $request
     * @param  string    $url URL鍦板潃
     * @param  string    $namespace 鍛藉悕绌洪棿
     * @return CallbackDispatch
     */
    protected function bindToNamespace(Request $request, string $url, string $namespace): CallbackDispatch
    {
        $array  = explode('|', $url, 3);
        $class  = !empty($array[0]) ? $array[0] : $this->router->config('default_controller');
        $method = !empty($array[1]) ? $array[1] : $this->router->config('default_action');
        $param  = [];

        if (!empty($array[2])) {
            $this->parseUrlParams($array[2], $param);
        }

        return new CallbackDispatch($request, $this, [$namespace . '\\' . Str::studly($class), $method], $param);
    }

    /**
     * 缁戝畾鍒版帶鍒跺櫒
     * @access protected
     * @param  Request   $request
     * @param  string    $url URL鍦板潃
     * @param  string    $controller 鎺у埗鍣ㄥ悕
     * @return ControllerDispatch
     */
    protected function bindToController(Request $request, string $url, string $controller): ControllerDispatch
    {
        $array  = explode('|', $url, 2);
        $action = !empty($array[0]) ? $array[0] : $this->router->config('default_action');
        $param  = [];

        if (!empty($array[1])) {
            $this->parseUrlParams($array[1], $param);
        }

        return new ControllerDispatch($request, $this, $controller . '/' . $action, $param);
    }

}
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号