初始kohana(二)-----------kohana3.3 生命周期

入口:index.php
    获取地区
    常规常量设置
    引入application\classes\common\env文件获取开发环境
    引入application\classes\common\area标记地区
    
    引入 bootstrap 启动程序
        引入Kohana_Core核心类
            初始化程序
        引入 kohana继承空类
        
        设置时区、语言、自动加载方法
        设置kohana初始选项
        加载logs、config读取类
        enable kohana模块
        
        设置路由
            此处通过set方法保存路由信息
            
                public static function set($name, $uri = NULL, $regex = NULL)
                {
                    return Route::$_routes[$name] = new Route($uri, $regex);
                }
            在request实例化时会读取路由信息进行匹配
        
    执行request
        echo Request::factory()
        
        
            Creates a new request object for the given URI. New requests should be
            created using the [Request::instance] or [Request::factory] methods.
            
            
            1.获取请求配置信息
                cli模式
                
                http模式
                    SERVER_PROTOCOL、REQUEST_METHOD、HTTPS、HTTP_REFERER、HTTP_USER_AGENT、HTTP_X_REQUESTED_WITH、HTTP_X_FORWARDED_FOR
                    查询http协议中是否设定,未设定则取项目默认值
                    
            2.Request::$initial = $request = new Request($uri, $cache);
            实例化Request
            
            3.设置protocol 默认为 http/1.1 并保存 get->query  post->post 数据
                设置安全、请求方法、referrer、body
            
            
            
        execute()
        
            * Processes the request, executing the controller action that handles this
            * request, determined by the [Route].
             *
             * 1. Before the controller action is called, the [Controller::before] method
             * will be called.
             * 2. Next the controller action will be called.
             * 3. After the controller action is called, the [Controller::after] method
             * will be called.    

            通过 request_client 实例调用excute方法,创建一个response实例,然后通过request_client_internal调用excute_request方法
            通过反射类来调用控制器中的方法返回response,同时在excute_request中计算方法耗时和内存消耗
                关键代码:
                        // Load the controller using reflection
                        $class = new ReflectionClass($prefix.$controller);
                        
                        // Create a new instance of the controller
                        $controller = $class->newInstance($request, $response);

                        // Run the controller's execute() method
                        $response = $class->getMethod('execute')->invoke($controller);
        
        
                执行excute时,会先调用before(),再执行action,最后执行 after()
                
                
            最后执行response回调函数(暂时未深入了解用法)
        
        send_headers()
        
            Sends the response status and all set headers.
            主要设置协议头部返回信息
            
            
        body();      echo 最后的内容 生命周期结束
        
        if ($content === NULL)
        {
            // Act as a getter
            return $this->_body;
        }

        // Act as a setter
        $this->_body = $content;

        return $this;
        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值